#41580 [NEW]: preg_replace returns NULL, not the unmodified string
| From: | steponas at idamas dot net | Date: | Mon, 04 Jun 2007 07:01:37 +0000 |
| Subject: | #41580 [NEW]: preg_replace returns NULL, not the unmodified string | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-113320@lists.php.net to get a copy of this message | ||
From: steponas at idamas dot net
Operating system: All
PHP version: 5.2.3
PHP Bug Type: PCRE related
Bug description: preg_replace returns NULL, not the unmodified string
Description:
------------
Hello,
the problem is, on this specific string (which I managed to write by
accident) preg_replace returns NULL, not the unmodified string (because the
regexp isn't matched).
The funny thing is, if I remove some chars from the end of the string, or
if I remove all "[quote]" ocurences from the search string, or if I provide
a closing tag for the quote ([/quote]) - it works ok (returns the original
string). And this bug (as I see it) is found only in PHP 5.2.*.
My current sysinfo:
Windows XP sp2
PHP 5.2.3 as Apache2.2 cli (from binary .zip)
PCRE Library Version 7.0 18-Dec-2006
PHP versions I tested it on:
5.2.3 - bad
5.2.1 - bad
5.2.0 - bad
5.1.6 - ok, returns the string
4.3.10 - ok
4.3.2 - ok
It works the same on linux and windows.
Reproduce code:
---------------
<?php header("Content-type: text/html; charset=utf-8"); ?>
<pre>
<?php
//base64_encoded, because it's UTF-8, Lithuanian
$string =
base64_decode("VcW+ZHJhdXN0YSBmb3J1bXVvc2UgcmHFoXl0aSBjaXRhdMWzIHBha2xvZGVz".
"IC0gdC55LiwgamVpZ3UgcmHFoXlzaXRlIDMtaXItZGF1Z2lhdSBuZQ0KdcW+ZGFyeXRhcyBjaW".
"F0YXRhcyAoW3F1b3RlXS4uLltxdW90ZV0uLi5bcXVvdGVdLi4uKSwgdGFpIGp1bXMgYnVzIGFw".
"aWUgdGFpIHByYW5lxaF0YSBpciDFvmludQ0KdMSXIG5lYnVzIGnFoXNpxbNzdGEgLSBz");
echo "The string is:\n".$string."\n\n";
echo "PHP: ".phpversion()."\n";
$regexp = "/\[quote\]((\s|.)*)\[\/quote\]/i";
echo (preg_match($regexp, $string) == true ? "Match found\n" : "Match not
found\n").
"var_dump( preg_replace(...) ): ";
var_dump( preg_replace($regexp, "<span style='background_color:
yellow;'>\$1</span>", $string) );
?>
</pre>
Expected result:
----------------
var_dump( preg_replace(...) ): <The original string>
Actual result:
--------------
var_dump( preg_replace(...) ): NULL
--
Edit bug report at http://bugs.php.net/?id=41580&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=41580&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=41580&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=41580&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=41580&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=41580&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=41580&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=41580&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=41580&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=41580&r=support
Expected behavior: http://bugs.php.net/fix.php?id=41580&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=41580&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=41580&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=41580&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=41580&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=41580&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=41580&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=41580&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=41580&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=41580&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=41580&r=mysqlcfg