Bug #81349 [Asn->Csd]: mb_detect_encoding misdetcts ASCII in some cases

From: Date: Wed, 11 Aug 2021 09:37:11 +0000
Subject: Bug #81349 [Asn->Csd]: mb_detect_encoding misdetcts ASCII in some cases
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-235750@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81349&edit=1 ID: 81349 Updated by: git@php.net Reported by: phofstetter at sensational dot ch Summary: mb_detect_encoding misdetcts ASCII in some cases -Status: Assigned +Status: Closed Type: Bug Package: mbstring related Operating System: macOS PHP Version: 8.1.0beta2 Assigned To: nikic Block user comment: N Private report: N New Comment: Automatic comment on behalf of nikic Revision: https://github.com/php/php-src/commit/28500fe4ef1218e04e830ae94d889c4b6c67940d Log: Fixed bug #81349 Previous Comments: ------------------------------------------------------------------------ [2021-08-11 09:24:27] phofstetter at sensational dot ch Description: ------------ mb_detect_encoding() seems to have changed quite a bit between PHP 8.0 and 8.1 and mostly for the better, TBH. However, here's a test case where it misdetects a string as being ASCII when it absolutely cannot be because byte 0 is outside of the 7bit range of ASCII. If byte 1 is any non-letter character aside of space, the misdetection will happen. If it's any letter or space, it's fine. While in <= PHP 8.0, the function had it's quirks, it would never detect a string with a character with its high-bit set as ASCII. Test script: --------------- <?php echo(mb_detect_encoding("\xe4,a", ['ASCII', 'UTF-8', 'ISO-8859-1'])."\n"); echo(mb_detect_encoding("\xe4 a", ['ASCII', 'UTF-8', 'ISO-8859-1'])."\n"); Expected result: ---------------- ISO-8859-1 ISO-8859-1 Actual result: -------------- ASCII ISO-8859-1 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=81349&edit=1

« previous php.bugs (#235750) next »