🐛 fix(translation): preserve emoji characters in suggestion_array JSON#4594
Open
mauretto78 wants to merge 1 commit into
Open
🐛 fix(translation): preserve emoji characters in suggestion_array JSON#4594mauretto78 wants to merge 1 commit into
mauretto78 wants to merge 1 commit into
Conversation
- replace FILTER_SANITIZE_SPECIAL_CHARS with FILTER_UNSAFE_RAW for the suggestion_array parameter to prevent corruption of multi-byte UTF-8 characters (emojis, 4-byte unicode) - add explicit JSON validation via json_decode() to reject malformed input while preserving valid JSON strings intact - add unit tests covering emoji preservation and invalid JSON rejection
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes corruption/truncation of suggestion_array JSON when it contains 4‑byte UTF‑8 characters (e.g., emojis) by changing request filtering and adding JSON validity handling, with accompanying unit tests.
Changes:
- Switch
suggestion_arrayfiltering fromFILTER_SANITIZE_SPECIAL_CHARStoFILTER_UNSAFE_RAWto preserve emojis. - Add inline JSON validation logic for
suggestion_arrayduring request validation. - Add unit tests covering emoji preservation and invalid JSON handling.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
lib/Controller/API/App/SetTranslationController.php |
Adjusts filtering/validation of suggestion_array before it’s used/persisted. |
tests/unit/Controllers/SetTranslationControllerTest.php |
Adds tests intended to assert emoji-safe handling and invalid JSON behavior. |
🧪 Test-Guard Report❌ FAIL — Some changed source files lack adequate test coverage. Coverage Analysis: ❌ FAILChanged lines: 0.0% covered (threshold: 80%) 📋 1 files: 1 ❌ fail
Test File Matching: ✅ PASSFile matching: 1 pass 📋 1 files: 1 ✅ pass
Per-File Evaluation: ❌ FAILAll files resolved by deterministic shortcuts. 📋 1 files: 1 ❌ fail
Result: ❌ FAIL Why this FAIL?
To resolve: add or enhance tests in tests/unit/Controllers/SetTranslationControllerTest.php to cover the changed lines in lib/Controller/API/App/SetTranslationController.php. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix
suggestion_arraypersistence when the JSON payload contains emoji characters.FILTER_SANITIZE_SPECIAL_CHARSwas stripping/corrupting 4-byte UTF-8 sequences (emojis), producing truncated invalid JSON stored in the database.Type
fix— bug fixChanges
lib/Controller/API/App/SetTranslationController.phpFILTER_SANITIZE_SPECIAL_CHARSwithFILTER_UNSAFE_RAWforsuggestion_array; add explicit JSON validationtests/unit/Controllers/SetTranslationControllerTest.phpTesting
vendor/bin/phpunit --exclude-group=ExternalServices --no-coveragepassesAI Disclosure
GitHub Copilot (Claude)
Notes
Root cause:
FILTER_SANITIZE_SPECIAL_CHARSencodes"as"and strips high bytes (including 4-byte UTF-8 emoji sequences), breaking the JSON structure. The old code also had a confusing['filter' => FILTER_UNSAFE_RAW, ...]option array which is invalid forfilter_var()(that syntax is forfilter_var_array()), so the intendedFILTER_UNSAFE_RAWwas never actually applied.