From: pilotv at rambler dot ru
Operating system: All
PHP version: 4.4.4
PHP Bug Type: PCRE related
Bug description: Subpattern is not captured for backreference in some cases
Description:
------------
(Sorry for my english)
Subpattern is not captured for backreference if it is followed by '?' and
does not appear in subject string.
Reproduce code:
---------------
<?
$str=<<<EOD
<a href="aaa">
<a href='aaa'>
<a href=aaa>
EOD;
// Following RE works properly
$re='/<a href=(["\']?)(\w+)\1>/iS';
preg_match_all($re,$str,$regs,PREG_SET_ORDER);
print_r($regs);
// Following RE works wrong
$re='/<a href=(["\'])?(\w+)\1>/iS';
preg_match_all($re,$str,$regs,PREG_SET_ORDER);
print_r($regs);
?>
Expected result:
----------------
// Produced by 1st RE:
Array
(
[0] => Array
(
[0] => <a href="aaa">
[1] => "
[2] => aaa
)
[1] => Array
(
[0] => <a href='aaa'>
[1] => '
[2] => aaa
)
[2] => Array
(
[0] => <a href=aaa>
[1] =>
[2] => aaa
)
)
Actual result:
--------------
// Produced by 2nd RE:
Array
(
[0] => Array
(
[0] => <a href="aaa">
[1] => "
[2] => aaa
)
[1] => Array
(
[0] => <a href='aaa'>
[1] => '
[2] => aaa
)
)
--
Edit bug report at http://bugs.php.net/?id=38599&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=38599&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=38599&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=38599&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=38599&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=38599&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=38599&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=38599&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=38599&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=38599&r=support
Expected behavior: http://bugs.php.net/fix.php?id=38599&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=38599&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=38599&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=38599&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=38599&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=38599&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=38599&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=38599&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=38599&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=38599&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=38599&r=mysqlcfg