[php-src] PR #11239: Consider order of candidate encodings when guessing source encoding of input string
| From: | alexdowad | Date: | Sun, 14 May 2023 12:22:57 +0000 |
| Subject: | [php-src] PR #11239: Consider order of candidate encodings when guessing source encoding of input string | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-22512@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/11239
Author: alexdowad
In PHP 8.0 and before,
mb_detect_encoding (and some other functions which attempt to
'detect' input string encoding) would do so essentially just by trying a list of
candidates in order and picking the first candidate encoding in which the string was valid. In PHP
8.1, I made mb_detect_encoding use heuristics to try to choose the "most
likely" input string source encoding in cases where more than one candidate encoding is valid.
This patch retains those heuristics, but weights the candidate text encodings by their order, so
that those listed first are more likely to be chosen. This allows the caller to indicate what input
text encoding they believe is more likely to be the correct one, by listing it first. This brings
the behavior of mb_detect_encoding in closer harmony with the documentation.
Also, use @pakutoma's stricter validation code for ISO-2022-JP and UTF-7 to improve detection
accuracy even in "non-strict" detection mode.
Closes GH-10192.
FYA @cmb69 @Girgias @kamil-tekiela @youkidearitai @pakutoma @iluuu1994