Skip to content

🐛 fix(translation): preserve emoji characters in suggestion_array JSON#4594

Open
mauretto78 wants to merge 1 commit into
developfrom
fix-emoji-in-suggestion-array
Open

🐛 fix(translation): preserve emoji characters in suggestion_array JSON#4594
mauretto78 wants to merge 1 commit into
developfrom
fix-emoji-in-suggestion-array

Conversation

@mauretto78
Copy link
Copy Markdown
Contributor

@mauretto78 mauretto78 commented May 22, 2026

Summary

Fix suggestion_array persistence when the JSON payload contains emoji characters. FILTER_SANITIZE_SPECIAL_CHARS was stripping/corrupting 4-byte UTF-8 sequences (emojis), producing truncated invalid JSON stored in the database.

Type

  • fix — bug fix

Changes

File Change
lib/Controller/API/App/SetTranslationController.php Replace FILTER_SANITIZE_SPECIAL_CHARS with FILTER_UNSAFE_RAW for suggestion_array; add explicit JSON validation
tests/unit/Controllers/SetTranslationControllerTest.php Add unit tests proving emoji preservation and invalid JSON rejection

Testing

  • vendor/bin/phpunit --exclude-group=ExternalServices --no-coverage passes
  • New tests added for changed behavior
  • Regression tests added for bug fixes
PHPUnit 12.5.23 — OK (12 tests, 16 assertions)

AI Disclosure

  • AI tools were used — name the agent/tool below

GitHub Copilot (Claude)

Notes

Root cause: FILTER_SANITIZE_SPECIAL_CHARS encodes " 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 for filter_var() (that syntax is for filter_var_array()), so the intended FILTER_UNSAFE_RAW was never actually applied.


- 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
Copilot AI review requested due to automatic review settings May 22, 2026 08:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_array filtering from FILTER_SANITIZE_SPECIAL_CHARS to FILTER_UNSAFE_RAW to preserve emojis.
  • Add inline JSON validation logic for suggestion_array during 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.

Comment thread lib/Controller/API/App/SetTranslationController.php
Comment thread tests/unit/Controllers/SetTranslationControllerTest.php
Comment thread tests/unit/Controllers/SetTranslationControllerTest.php
@github-actions
Copy link
Copy Markdown

🧪 Test-Guard Report

❌ FAIL — Some changed source files lack adequate test coverage.

Coverage Analysis: ❌ FAIL

Changed lines: 0.0% covered (threshold: 80%)

📋 1 files: 1 ❌ fail
File Verdict Reason
lib/Controller/API/App/SetTranslationController.php ❌ fail 0% diff coverage < 80% threshold

Test File Matching: ✅ PASS

File matching: 1 pass

📋 1 files: 1 ✅ pass
File Verdict Reason
lib/Controller/API/App/SetTranslationController.php ✅ pass Test file modified in PR: tests/unit/Controllers/SetTranslationControllerTest.php

Per-File Evaluation: ❌ FAIL

All files resolved by deterministic shortcuts.

📋 1 files: 1 ❌ fail
File Verdict Reason
lib/Controller/API/App/SetTranslationController.php ❌ fail shortcut → coverage 0% < 80%, relevant tests exist but insufficient

Result: ❌ FAIL


Why this FAIL?

  • Coverage Analysis: lib/Controller/API/App/SetTranslationController.php has 0% coverage on changed lines, which is below the 80% threshold → tests do not exercise any changed code in this file.
  • Per-File Evaluation: Although relevant tests exist in tests/unit/Controllers/SetTranslationControllerTest.php, they do not sufficiently cover the changes in SetTranslationController.php → increase test coverage for changed code.

To resolve: add or enhance tests in tests/unit/Controllers/SetTranslationControllerTest.php to cover the changed lines in lib/Controller/API/App/SetTranslationController.php.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants