Repository navigation
Conversation
…_to_utf16() Each \uXXXX escape was converted on its own, so a JSON-style surrogate pair such as \uD83D\uDE00 became six bytes of invalid UTF-8 (CESU-8) in unicode_to_utf8() and "??" in unicode_to_utf16(). Match surrogate pairs first and decode them together as UTF-16BE. The mbstring checks are gone, because symfony/polyfill-mbstring is a hard requirement; without the extension the methods silently returned their input. unicode_to_utf16() returns UTF-8, which its docblock now says. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 13, 2026
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 of Changes
StringHelper::unicode_to_utf8()andunicode_to_utf16()convert each\uXXXXescape on its own. A surrogate pair, which is how JSON encodes characters outside the BMP, is not decoded into one character:Both methods now match a high/low surrogate pair first, case-insensitively, and decode the two code units together as UTF-16BE. All other escapes are converted as before:
unicode_to_utf8()uses UCS-2BE andunicode_to_utf16()UTF-16BE, so a lone surrogate keeps its current result in both.Other changes in the same two methods:
extension_loaded('mbstring')checks are removed. Without the extension, the methods silently returned their input, butsymfony/polyfill-mbstringis a hard requirement and providesmb_convert_encoding().unicode_to_utf16()has always returned UTF-8, as the existing tests expect, but its docblock said "UTF-16 string". The docblock now says it returns UTF-8. Deprecating the misleadingly named method instead would be a separate decision.Testing Instructions
seedTestUnicodeToUtf8andseedTestUnicodeToUtf16get three new cases each: a surrogate pair, a pair in lowercase hex, and a pair between two BMP escapes. All six fail before the change and pass after it.vendor/bin/phpunitis green, phpcs is clean, and PHPStan reports no errors locally. The PHPStan job in CI fails on4.x-devas well (mb_trimand the other PHP 8.4 polyfill functions are not found), and #66 fixes that.Documentation Changes Required
docs/overview.md(still "TODO" on4.x-dev) gets a section onunicode_to_utf8()andunicode_to_utf16(). The owner's docs PR #72 does not describe these methods, but it rewritesdocs/overview.md, so whichever is merged second has to fold this section into #72's structure. #73, #75, #77 and #78 also append sections to the stub, so expect small conflicts there.🤖 Generated with Claude Code