php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76708 mb_detect_encoding behaves inconsistenly depending on the argument type
Submitted: 2018-08-05 05:51 UTC Modified: 2018-08-05 06:21 UTC
From: smokey101stair at gmail dot com Assigned:
Status: Duplicate Package: mbstring related
PHP Version: Irrelevant OS: Irrelevant
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: smokey101stair at gmail dot com
New email:
PHP Version: OS:

 

 [2018-08-05 05:51 UTC] smokey101stair at gmail dot com
Description:
------------
Similar to Bug 76704. mb_detect_encoding()'s second parameter, $encoding_list, takes either an array of encodings or a comma separated string of encodings. However, its behavior varies depending on whether an array or string is passed to $encoding_list, when that value contains both a supported and unsupported encoding.

Test script:
---------------
https://3v4l.org/KTBkK

Expected result:
----------------
Honestly.. I'm not entirely sure.

Setting mb_detect_encodings()'s second parameter is really doing the same thing as if you had passed the same thing to mb_detect_order(), which returns false (now that Bug 76704 is fixed) if any of the given encodings are not supported. 

Option 1) In the interest of consistency, this should probably also return false if any of the given encodings are not supported. Doing this would probably be a a BC break, and I don't know how popular this function really is.

Option 2) Match what is currently done when an array is given and emit a warning and silently fallback to the value of mb_detect_order().

Option 3) Match what is currently done when a string is given and silently try to match against any of the supported encodings.



Actual result:
--------------
If $encoding_list is a string, and tries to match the given string against the supported encoding. No warning is emitted.

If $encoding_list is an array, then a warning is emitted and it tries to match the given string against the fallback value of mb_detect_order().

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-08-05 06:10 UTC] requinix@php.net
-Status: Open +Status: Duplicate
 [2018-08-05 06:10 UTC] requinix@php.net
Same cause as the other bug so this got fixed too.
 [2018-08-05 06:17 UTC] requinix@php.net
Oh. To be clear, the new behavior has the function issue a warning and use the mb_detect_order value. So option 2.
 [2018-08-05 06:21 UTC] smokey101stair at gmail dot com
Thanks for the explanation.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 00:01:29 2024 UTC