|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-03-17 19:19 UTC] crisp at xs4all dot nl
Description:
------------
The new pcre.backtrack_limit configuration directive is by default too restrictive (100.000) which results in failure of many - often quite simple - regular expressions.
I take it that this directive overrules the default setting for MATCH_LIMIT in PCRE which will also imply that the naming of this directive is wrong since MATCH_LIMIT is for every match() call in PCRE, not only those for backtracking.
It would make more sense to change the default of both pcre.backtrack_limit and pcre.recursion_limit to the ones that PCRE itself also supplies (10.000.000 for both) - that way there won't be a compatibility problem with previous versions of PHP as we have now.
Reproduce code:
---------------
$a = 'baab' . str_repeat('a', 100024);
$b = preg_replace('/b.*b/', '', $a);
Expected result:
----------------
I would expect $b to contain 100024 times 'a'
Actual result:
--------------
$b is a nullpointer, preg_last_error() reports '2' which is PREG_BACKTRACK_LIMIT_ERROR
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 23 05:00:01 2025 UTC |
For me this new behaviour have broken my templates system. While some of regexpes where simplified, others could not be done so. In some situations increasing these numbers of little help. For instance(the regexp was simplified greatly, in real-life application it is much more complex): <?php echo preg_replace('/\$[a-z]+([a-z]*(?:\[[a-z]*\])?)*/i' , 'replaced', '$abc $something[something]'); echo var_dump(preg_last_error()); ?> Expected result - 'replaced replaced replaced'. Actual result - nothing, NULL returned, preg_last_error() shows that there is PREG_BACKTRACK_LIMIT_ERROR error. Also increasing backtrack limit leads to another error, PREG_RECURSION_LIMIT_ERROR. Increasing recursion limit leads to php hanging up. Changing first or second asterisk in pattern to plus sign immediately fixes the problem, but I need it in this way. Also, do you think that this is a correct behaviour? I thing there is a bug somewhere that way. However, this works pretty well on php 4.x, 5.x and even at 5.2.1 (at one of the hosts), but it does not work on my local php5.2.2 on WinXPsp2.