php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38599 Subpattern is not captured for backreference in some cases
Submitted: 2006-08-25 21:02 UTC Modified: 2006-08-28 06:15 UTC
From: pilotv at rambler dot ru Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 4.4.4 OS: All
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: pilotv at rambler dot ru
New email:
PHP Version: OS:

 

 [2006-08-25 21:02 UTC] pilotv at rambler dot ru
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
        )

)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-25 21:38 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip


 [2006-08-25 23:17 UTC] pilotv at rambler dot ru
Sorry, I can not compile PHP myself here.
But I tryed latest available for download version 5.1.6. This bug is still present in it.
 [2006-08-28 06:15 UTC] tony2001@php.net
PCRE problems and limitations are not PHP problems.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 12:01:30 2024 UTC