Skip to content

[Mbstring] Use big-endian UCS-2 like ext/mbstring - #721

Merged
nicolas-grekas merged 1 commit into
symfony:1.xfrom
wleeaf:mbstring-ucs2-big-endian
Oct 28, 2026
Merged

nicolas-grekas merged 1 commit into
symfony:1.xfrom
wleeaf:mbstring-ucs2-big-endian

Conversation

@wleeaf

@wleeaf wleeaf commented Oct 24, 2026

Copy link
Copy Markdown
Contributor
Q A
Branch? 1.x
Bug fix? yes
New feature? no
Deprecations? no
Issues -
License MIT

ext/mbstring encodes and decodes UCS-2 as big-endian. The polyfill passes the name to iconv unchanged. glibc's iconv treats UCS-2 without a BOM as host byte order, so on x86 the polyfill produces and reads little-endian data:

bin2hex(mb_convert_encoding('Aé', 'UCS-2', 'UTF-8'));
// ext/mbstring: '004100e9'
// polyfill:     '4100e900'

Decoding big-endian UCS-2 produced by ext/mbstring or another system gives the wrong characters as well. getEncoding() already maps UTF-16 and UTF-32 to their big-endian names for the same reason. This adds UCS-2 to that list.

The new assertions in testConvertEncoding() cover both directions with the polyfill. They fail without the change on glibc and pass with it. Converting BMP text to UCS-2 and back now gives the same bytes as PHP 8.5's mbstring. ./phpunit tests/Mbstring passes.

Copilot AI balanced review requested due to automatic review settings October 24, 2026 15:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@nicolas-grekas

Copy link
Copy Markdown
Member

Thank you @wleeaf.

@nicolas-grekas
nicolas-grekas merged commit 3c07aa7 into symfony:1.x Oct 28, 2026
20 checks passed
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.

3 participants