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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: cmb@php.net
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Wed Nov 06 15:01:29 2024 UTC