Fix/ambigous charset#30
Merged
Merged
Conversation
Added a mapping of charset aliases to unambiguous ICU names for UConverter.
Collaborator
Author
|
@ralflang I am really not sure obout this PR, please conduct a full depth review |
ralflang
approved these changes
May 29, 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.
Silence UConverter “ambiguous encoding” warnings for common charsets
Summary
CharacterSets::toUConverter()to map charset names that ICU treats as ambiguous to stable canonical names before constructingUConverter.toUConverter()for both source and destination encodings inHordeString::_convertCharset()(and the legacyHorde_Stringwrapper).windows-1258and pass-through behavior for unambiguous charsets.Problem
When iconv and mbstring cannot convert a string,
HordeString::_convertCharset()falls back to PHP’s intlUConverter. Several widely used charset labels are ambiguous in ICU: PHP accepts them but emits a warning and picks one canonical mapping, for example:This is commonly triggered by
windows-1258(Vietnamese), which Horde lowercases from MIME labels likeWindows-1258. The warning appears on line 202 ofHordeString.phpand can flood Horde logs during mail/ActiveSync processing even though conversion succeeds.Other affected aliases include
big5-hkscs,shift_jis,tis-620,windows-936, andwindows-950.Solution
CharacterSetswith a small$uconverterMap(afternormalize()) that maps ambiguous aliases to the same ICU canonical names PHP would select anyway (e.g.windows-1258→cp1258, which resolves toibm-5354_P100-1998without a warning).CharacterSets::toUConverter($from)andCharacterSets::toUConverter($to)immediately beforenew UConverter($to, $from).windows-1258.Behavior is unchanged; only log noise is removed.
Files changed
src/CharacterSets.php$uconverterMap,toUConverter()src/HordeString.phptoUConverter()for UConverter fallbacklib/Horde/String.phptest/CharacterSetsTest.phptoUConverter()Test plan
new UConverter('utf-8', 'windows-1258')before/after — confirm noAmbiguous encodingwarning after the patch.HordeString::convertCharset('<html>', 'UTF-8', 'Windows-1258')returns unchanged ASCII (existingtestBug9528).vendor/bin/phpunit test/CharacterSetsTest.phppasses.ibm-5354_P100-1998warnings; confirm logs are clean and message bodies still display correctly for Vietnamese (windows-1258) content.