Bug #76127 [Opn->Ver]: preg_split does not raise an error on invalid UTF-8
Edit report at https://bugs.php.net/bug.php?id=76127&edit=1
ID: 76127
Updated by: cmb@php.net
Reported by: graefrath at femu dot rwth-aachen dot de
Summary: preg_split does not raise an error on invalid UTF-8
-Status: Open
+Status: Verified
Type: Bug
Package: PCRE related
PHP Version: 5.6.34
Block user comment: N
Private report: N
New Comment:
Confirmed: <https://3v4l.org/1WYQE>.
The problem is that although the error is detected[1],
php_pcre_split_impl() happily proceeds, while
php_pcre_match_impl() checks for an error in the end, and returns
FALSE in that case[2].
[1] <https://github.com/php/php-src/blob/PHP-7.2.4/ext/pcre/php_pcre.c#L2369>
[2] <https://github.com/php/php-src/blob/PHP-7.2.4/ext/pcre/php_pcre.c#L1134-L1139>
Previous Comments:
------------------------------------------------------------------------
[2018-03-21 13:36:09] graefrath at femu dot rwth-aachen dot de
Description:
------------
preg_match and preg_replace return false and set the last error to PREG_BAD_UTF8_ERROR when the u
modifier is specified and the subject is invalid UTF-8. However, preg_split does not behave
consistently in this regard.
Test script:
---------------
var_dump(preg_split("/a/u", "a\xff"));
Expected result:
----------------
preg_split should return false and set the last error PREG_BAD_UTF8_ERROR just like the other preg_
functions.
Actual result:
--------------
preg_split returns an array with the subject string.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76127&edit=1
Thread (3 messages)