php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69672 preg_replace() does not necessarily cater to u modifier
Submitted: 2015-05-20 14:22 UTC Modified: 2015-06-05 15:04 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: cmb@php.net Assigned:
Status: Duplicate Package: PCRE related
PHP Version: 5.6.9 OS: *
Private report: No CVE-ID: None
 [2015-05-20 14:22 UTC] cmb@php.net
Description:
------------
A user contributed note[1] mentions an "unexpected behavior" of
preg_replace() with regard to matching only an empty subpattern.
In my opinion, this is a bug, because UTF-8 encoded code points
must never be split when the u modifier is set. Matching for an
empty subpattern only might be regarded as a bug per se, but then
at least a warning should be raised or an error should be reported
by preg_last_error().

According to <http://3v4l.org/AMq5N> the current behavior has been
introduced with PHP 5.2.9, and is not directly related to the PCRE
library.

[1] <http://php.net/manual/en/function.preg-replace.php#117314>


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

var_dump(preg_replace('/()/u', '*', "a\xc3\x84b"));

?>


Expected result:
----------------
string(8) "*a*Ä*b*"


Actual result:
--------------
string(9) "*a*�*�*b*"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-05 15:04 UTC] cmb@php.net
-Status: Open +Status: Duplicate
 [2015-06-05 15:04 UTC] cmb@php.net
Duplicate of bug #53823.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Nov 12 08:01:35 2019 UTC