### Description The following code: https://3v4l.org/3cnGD/rfc#vgit.master ```php <?php echo mb_detect_encoding('abc', 'UTF8, ASCII'); ``` Resulted in this output: ``` Fatal error: Uncaught ValueError: mb_detect_encoding(): Argument #2 ($encodings) contains invalid encoding "UTF8" ``` But I expected this output instead: ``` UTF-8 ``` This is a regression, see https://3v4l.org/3cnGD And this works if the list is given as an array: https://3v4l.org/lVva0/rfc#vgit.master ### PHP Version PHP 8.4 ### Operating System _No response_
Activity
cmb69 commentedon Sep 10, 2024
Not sure when or why this has been changed, but using
"UTF-8"is still supported (https://3v4l.org/8HA6Q/rfc#output).youkidearitai commentedon Sep 10, 2024
Hmm. Seems could not catch at
mbfl_name2encoding_ex.cmb69 commentedon Sep 10, 2024
According to git bisect, 3ad422e is the culprit. Maybe @nielsdos can have a look at this issue.
youkidearitai commentedon Sep 10, 2024
UTF8is alias ofUTF-8. Originally, catch below:php-src/ext/mbstring/libmbfl/mbfl/mbfl_encoding.c
Lines 369 to 378 in 3ad422e
However,
strcasecmpcan't catch variablenamein"UTF8, ASCII".I understanding only this.
ndossche commentedon Sep 10, 2024
The problem is simply that the loops below should use strncasecmp to take into account the length. Will fix this evening.
youkidearitai commentedon Sep 10, 2024
@nielsdos I tried create pull request. Feel free to comment. Thank you.
#15829
Fix GH-15824 mb_detect_encoding() invalid "UTF8" (#15829)
[skip ci] Add NEWS for phpGH-15824
[skip ci] Add NEWS for phpGH-15824
Fix phpGH-15824: Fix NEWS position
[skip ci] Add NEWS for GH-15824 (GH-15835)