ID: 49333
Updated by: [email protected]
Reported By: inf3rno dot hu at gmail dot com
-Status: Open
+Status: Bogus
Bug Type: PCRE related
Operating System: Windows XP
PHP Version: 5.2.10
New Comment:
You can abuse things to some extend but there's a limit always. And
this is not PHP bug anyway (if a bug at all) but PCRE lib.
Previous Comments:
------------------------------------------------------------------------
[2009-08-25 10:05:57] inf3rno dot hu at gmail dot com
Original pattern was this:
'%(?<string>.*?)(?:{\\s*(?<function>[a-z0-9_]+)(?:\\s*(?:(?<hash>(?:(?:\\s+[a-z0-9_]+\\s*=\\s*)?(?:\\$[a-z0-9_]+(?:->[a-z0-9_]+|\\.[a-z0-9_]+)*|\\d+(?:\\.\\d+)?|".*?(?:\\\\".*?)*"))+)|(?<chain>(?:(?:\\s+[a-z0-9_]+(?:
[a-z0-9_]+)*\\s+)?(?:\\$[a-z0-9_]+(?:->[a-z0-9_]+|\\.[a-z0-9_]+)*|\\d+(?:\\.\\d+)?|".*?(?:\\\\".*?)*"))+)|(?<list>(?:\\$[a-z0-9_]+(?:->[a-z0-9_]+|\\.[a-z0-9_]+)*|\\d+(?:\\.\\d+)?|".*?(?:\\\\".*?)*")(?:\\s*,\\s*(?:\\$[a-z0-9_]+(?:->[a-z0-9_]+|\\.[a-z0-9_]+)*|\\d+(?:\\.\\d+)?|".*?(?:\\\\".*?)*"))*)))?(?:\\s*}(?<block>.*?(?:(?R).*?)*?){\\s*/(?P=function))?\\s*}|{\\s*\\$(?<variable>[a-z0-9_]+(?:->[a-z0-9_]+|\\.[a-z0-9_]+)*)\\s*}|{\\s*\\*(?<comment>.*?)\\*\\s*}|$)%sDu'
This pattern matches on similar tokens like Smarty uses.
I need the
%string_before(?:function_with_recursive_block|variable|comment|$)%
structure because I have to capture the string before the token too, and
the fastest way for that is this.
With offset capture and a
%function_with_recursive_block|variable|comment% structured regex I can
do this too, but it's the slower way, cause I have to call strlen and
substr functions in a loop.
So I need that .*? :-)
But recursive patterns have a strange behavior.
I thought that '%.*?(?:([a-z])(?:(?R)*?\1)?|$)%sD' has to work too, but
it didn't. Logically, the (?R)*? means here:
"string+token...+string+end_of_the_recursive_part", but "$" is the end
of the whole string, and not the end of the recursive part. :S
------------------------------------------------------------------------
[2009-08-25 08:47:29] j dot boggiano at seld dot be
I am not entirely sure what you are trying to achieve so maybe I broke
some functionality, but with this pattern at least it gives the expected
result with \r\n or \n (of course \n has less chars..)
$pattern='%\s*(?:([a-z])(?:.*?(?:(?R).*?)*?\1)?|$)%sD';
Is that good enough ?
------------------------------------------------------------------------
[2009-08-25 08:35:43] [email protected]
When the $test contains \r\n instead of \n it fails.
------------------------------------------------------------------------
[2009-08-24 12:21:40] inf3rno dot hu at gmail dot com
I reproduced it on another computer with the latest WAMPServer (Apache
2.2.11, PHP 5.3.0). I copied the code from here.
------------------------------------------------------------------------
[2009-08-24 11:20:39] inf3rno dot hu at gmail dot com
Yes, I can reproduce it.
Tried with alternative text editor, but same result. So I think it's
not memory or text editor problem. (Btw. I'll test my computer's memory
soon.)
I'll try it out after a reinstall, maybe some dll files are damaged.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/49333
--
Edit this bug report at http://bugs.php.net/?id=49333&edit=1