Bug #69309 [Opn->Nab]: preg_replace return NULL on certain string
| From: | cmb@php.net | Date: | Thu, 26 Mar 2015 14:47:14 +0000 |
| Subject: | Bug #69309 [Opn->Nab]: preg_replace return NULL on certain string | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-191622@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=69309&edit=1
ID: 69309
Updated by: cmb@php.net
Reported by: dodothedreamer at gmail dot com
Summary: preg_replace return NULL on certain string
-Status: Open
+Status: Not a bug
Type: Bug
Package: *Regular Expressions
Operating System: Ubuntu
PHP Version: 5.4.39
Block user comment: N
Private report: N
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
> preg_last_error() return 2.
That is PREG_BACKTRACK_LIMIT_ERROR. Increasing pcre.backtrack_limit
to 10,000,000 is sufficient to process the provided test script.
However, I suggest you simplify the regex in combination with
preg_replace_callback().
Previous Comments:
------------------------------------------------------------------------
[2015-03-26 14:21:40] dodothedreamer at gmail dot com
Description:
------------
I saw this bug on PHP version 5.4.32 and also on 5.5.9-1ubuntu4.7
When you enter a certain string ( see the test script) to preg_replace, it returns NULL. Some small
changes in the string don't cause this error, for example if you delete one of the
"a" characters from the end, then the bug doesn't happen.
preg_last_error() return 2.
Increasing pcre.backtrack_limit and pcre.recursion_limit does not help ( the regex engine seems to
get stuck in a loop for a long time )
Test script:
---------------
$returnValue = preg_replace('#\\<figure +.*?\\>\\<img
+(.+?)/\\>.*?\\<figcaption\\>\\<a
href="(.+?)".*?\\>(.*?)\\</a\\>\\</figcaption\\>.*?\\</figure\\>#s',
'<figure class="caption"><a href="$2"><img $1/></a>
<figcaption><a href="$2">$3</a></figcaption>
</figure>', '<figure class="caption"
style="float:left"><img alt="×ת×××
××§× ××××× ×××¢×× × ×××××× ×× ×¢×
×××¡× ×××× "
onmouseup="this.src="graphic/img1530.jpg"" src="img1530.jpg" />
<figcaption><a href="http://tivonim-blog.co.il/%D7%A7%D7%A0%D7%99%D7%99%D7%93%D7%9C%D7%9A-%D7%98%D7%91%D7%A2%D7%95%D7%A0%D7%99-%D7%9E%D7%95%D7%A9%D7%9C%D7%9D-%D7%9E%D7%A8%D7%A7/">×ת×××
××§× ××××× ×××¢×× × </a>××××××
"×× ×¢× ×××¡× ××××" </figcaption>
</figure>
<p>×× ×ת ר×ש×× ×ת, ס××××
×ת×ספ×ת:</p>
<p><strong style="font-size: 10pt;"><a
href="art160.html">ס×× ×¤×פ×××
×§×××××</a></strong></p>
<p><strong style="font-size: 10pt;"><a
href="art161.html">ס×× ×ס×, ס××¨× ××××××
×××</a></strong></p>
<p><strong style="font-size: 10pt;"><a
href="art162.html">ס×× ×¡××§</a></strong></p>
<p><strong style="font-size: 10pt;"><a
href="art198.html">×ספר××ס ×ש××פ××
×שק×××</a></strong></p>
<p><span style="font-size: 10pt;">×רק××:</span></p>
<p><strong style="font-size: 10pt;"><a href="http://veg.anonymous.org.il/art283.html">×רק
×§××× ×××</a></strong></p>
<p><strong style="font-size: 10pt;"><a
href="art178.html">×רק ×צ×</a></strong></p>
<p><span style="font-size: 10pt;">×× ×ת
×¢×קר××ת:</span></p>
<p><strong style="font-size: 10pt;"><a href="http://veg.anonymous.org.il/art552.html">ת×ת××ת
×ר××ש××§ ××××××ת
×§×× ×××</a></strong></p>
<p><strong style="font-size: 10pt;"><a href="http://veg.anonymous.org.il/art627.html">פ×ר××ת
××××××ת ×קר×
××××××</a></strong></p>
<p><a href="http://veg.anonymous.org.il/art347.html"
style="font-size: 10pt;"><b>×§×× ××× ×עש××
ת××××</b></a></p>
<p><strong style="font-size: 10pt;"><a
href="art229.html">תפ××-×××× ××קר×
×××× ×§××§×ס ×תר×</a></strong></p>
<p><span style="font-size:
10pt;">×§×× ××××:</span></p>
aaaaaaaaaa
');
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69309&edit=1