Bug #69672 [NEW]: preg_replace() does not necessarily cater to u modifier
| From: | cmb@php.net | Date: | Wed, 20 May 2015 14:22:52 +0000 |
| Subject: | Bug #69672 [NEW]: preg_replace() does not necessarily cater to u modifier | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-192786@lists.php.net to get a copy of this message | ||
From: cmb
Operating system: *
PHP version: 5.6.9
Package: PCRE related
Bug Type: Bug
Bug description:preg_replace() does not necessarily cater to u modifier
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*"
--
Edit bug report at https://bugs.php.net/bug.php?id=69672&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69672&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69672&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69672&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69672&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69672&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69672&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69672&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69672&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69672&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69672&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69672&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69672&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69672&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69672&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69672&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69672&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69672&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69672&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69672&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69672&r=mysqlcfg