Bug #81366 [NEW]: mb_detect_encoding behaving different and failing to detect UTF-8

From: Date: Mon, 16 Aug 2021 19:14:32 +0000
Subject: Bug #81366 [NEW]: mb_detect_encoding behaving different and failing to detect UTF-8
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-235882@lists.php.net to get a copy of this message
From:             martin at herndl dot org
Operating system: macOS
PHP version:      8.1.0beta2
Package:          mbstring related
Bug Type:         Bug
Bug description:mb_detect_encoding behaving different and failing to detect UTF-8

Description:
------------
mb_detect_encoding with ommited encodings (= null as argument =>
fallback to default detect order) behaves different on 8.1.0beta2 and
fails to detect UTF-8 in some cases with out-of-the-box settings.

I noticed this via the
ApplicationTest::testRenderExceptionWithDoubleWidthCharacters test
from Symfony in https://github.com/symfony/symfony/issues/41552
that
broke because it converted UTF-8 to UTF-8 again.

Test script:
---------------
<?php

var_dump(mb_detect_order());
var_dump(mb_detect_encoding('コマンドの実行中にエラーが発生しました。',
null, true));
var_dump(mb_detect_encoding('コマンドの実行中にエラーが発生しました',
null, true));

Expected result:
----------------
array(2) {
  [0]=>
  string(5) "ASCII"
  [1]=>
  string(5) "UTF-8"
}
string(5) "UTF-8"
string(5) "UTF-8"

Actual result:
--------------
array(2) {
  [0]=>
  string(5) "ASCII"
  [1]=>
  string(5) "UTF-8"
}
string(5) "ASCII"
string(5) "UTF-8"

-- 
Edit bug report at https://bugs.php.net/bug.php?id=81366&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=81366&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=81366&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=81366&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=81366&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=81366&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=81366&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=81366&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=81366&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=81366&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=81366&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81366&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=81366&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=81366&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=81366&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=81366&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=81366&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=81366&r=mysqlcfg


Thread (4 messages)

« previous php.bugs (#235882) next »