Bug #66664 [NEW]: preg_match_all + PREG_PATTERN_ORDER + PCRE_INFO_JCHANGED, output wrong result
| From: | coolwust at gmail dot com | Date: | Fri, 07 Feb 2014 19:03:42 +0000 |
| Subject: | Bug #66664 [NEW]: preg_match_all + PREG_PATTERN_ORDER + PCRE_INFO_JCHANGED, output wrong result | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-184199@lists.php.net to get a copy of this message | ||
From: coolwust at gmail dot com
Operating system: 3.12-1-amd64 Debian 3.12.
PHP version: 5.5.9
Package: PCRE related
Bug Type: Bug
Bug description:preg_match_all + PREG_PATTERN_ORDER + PCRE_INFO_JCHANGED, output wrong result
Description:
------------
---
From manual page: http://www.php.net/function.preg-match-all
---
The code is from pcre manual, chapter 'NAMED SUBPATTERNS', line 6093:
http://www.pcre.org/pcre.txt
PREG_SET_ORDER:
Output the same result as the manual expected.
PREG_PATTERN_ORDER
Output the wrong result. Please check example for details.
Maybe the latest named capturing overwrite the previous result.
Test script:
---------------
$pattern = <<<'PATTERN'
/(?xJ)
(?<DN>Mon|Fri|Sun)(?:day)?|
(?<DN>Tue)(?:sday)?|
(?<DN>Wed)(?:nesday)?|
(?<DN>Thu)(?:rsday)?|
(?<DN>Sat)(?:urday)?
/
PATTERN;
$subject = "Monday\nThursday";
$result1 = preg_match_all($pattern, $subject, $matches1,
PREG_PATTERN_ORDER);
$result2 = preg_match_all($pattern, $subject, $matches2,
PREG_SET_ORDER);
echo 'subject:';
var_dump($subject);
echo 'pattern:';
var_dump($pattern);
echo 'flag PREG_PATTERN_ORDER:';
var_dump($matches1);
echo 'flag PREG_SET_ORDER:';
var_dump($matches2);
Expected result:
----------------
subject:
string 'Monday
Thursday' (length=15)
pattern:
string '/(?xJ)
(?<DN>Mon|Fri|Sun)(?:day)?|
(?<DN>Tue)(?:sday)?|
(?<DN>Wed)(?:nesday)?|
(?<DN>Thu)(?:rsday)?|
(?<DN>Sat)(?:urday)?
/' (length=123)
flag PREG_PATTERN_ORDER:
array (size=7)
0 =>
array (size=2)
0 => string 'Monday' (length=6)
1 => string 'Thursday' (length=8)
'DN' =>
array (size=2)
0 => string 'Mon' (length=0) //Expected
1 => string 'Thu' (length=0) //Expected
1 =>
array (size=2)
0 => string 'Mon' (length=3)
1 => string '' (length=0)
2 =>
array (size=2)
0 => string '' (length=0)
1 => string '' (length=0)
3 =>
array (size=2)
0 => string '' (length=0)
1 => string '' (length=0)
4 =>
array (size=2)
0 => string '' (length=0)
1 => string 'Thu' (length=3)
5 =>
array (size=2)
0 => string '' (length=0)
1 => string '' (length=0)
flag PREG_SET_ORDER:
array (size=2)
0 =>
array (size=3)
0 => string 'Monday' (length=6)
'DN' => string 'Mon' (length=3)
1 => string 'Mon' (length=3)
1 =>
array (size=6)
0 => string 'Thursday' (length=8)
'DN' => string 'Thu' (length=3)
1 => string '' (length=0)
2 => string '' (length=0)
3 => string '' (length=0)
4 => string 'Thu' (length=3)
Actual result:
--------------
subject:
string 'Monday
Thursday' (length=15)
pattern:
string '/(?xJ)
(?<DN>Mon|Fri|Sun)(?:day)?|
(?<DN>Tue)(?:sday)?|
(?<DN>Wed)(?:nesday)?|
(?<DN>Thu)(?:rsday)?|
(?<DN>Sat)(?:urday)?
/' (length=123)
flag PREG_PATTERN_ORDER:
array (size=7)
0 =>
array (size=2)
0 => string 'Monday' (length=6)
1 => string 'Thursday' (length=8)
'DN' =>
array (size=2)
0 => string '' (length=0) //Wrong
1 => string '' (length=0) //Wrong
1 =>
array (size=2)
0 => string 'Mon' (length=3)
1 => string '' (length=0)
2 =>
array (size=2)
0 => string '' (length=0)
1 => string '' (length=0)
3 =>
array (size=2)
0 => string '' (length=0)
1 => string '' (length=0)
4 =>
array (size=2)
0 => string '' (length=0)
1 => string 'Thu' (length=3)
5 =>
array (size=2)
0 => string '' (length=0)
1 => string '' (length=0)
flag PREG_SET_ORDER:
array (size=2)
0 =>
array (size=3)
0 => string 'Monday' (length=6)
'DN' => string 'Mon' (length=3)
1 => string 'Mon' (length=3)
1 =>
array (size=6)
0 => string 'Thursday' (length=8)
'DN' => string 'Thu' (length=3)
1 => string '' (length=0)
2 => string '' (length=0)
3 => string '' (length=0)
4 => string 'Thu' (length=3)
--
Edit bug report at https://bugs.php.net/bug.php?id=66664&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66664&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66664&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66664&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=66664&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=66664&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=66664&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=66664&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=66664&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=66664&r=support
Expected behavior: https://bugs.php.net/fix.php?id=66664&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=66664&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=66664&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=66664&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66664&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=66664&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=66664&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=66664&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=66664&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=66664&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=66664&r=mysqlcfg