php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62041 Fails when recursive group comes before reference
Submitted: 2012-05-15 19:13 UTC Modified: 2012-05-20 22:02 UTC
From: michael at squiloople dot com Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.4.3 OS: Windows Vista
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: michael at squiloople dot com
New email:
PHP Version: OS:

 

 [2012-05-15 19:13 UTC] michael at squiloople dot com
Description:
------------
When the recursive subpattern is captured after it is referenced:

(?2)?::(?>((?1)(?>:(?1)){0,4}):)?

It works fine. But when the capture comes before the reference it doesn't:

((?1)(?>:(?1)){0,4})?::(?>(?2):)?

The problem is the final ":" as other characters work fine. Replacing it with "\:" 
or "[:]" does not help.

Test script:
---------------
// Test 1
preg_match('/^(?>([a-f0-9]{1,4})(?>:(?1)){5}:|(?!(?:.*[a-f0-9]:){6,})(?2)?::(?>((?1)(?>:(?1)){0,4}):)?)(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?>\.(?3)){3}$/iD', '0:0:0:0::0:255.255.255.255');

// Test 2
preg_match('/^(?>([a-f0-9]{1,4})(?>:(?1)){5}:|(?!(?:.*[a-f0-9]:){6,})((?1)(?>:(?1)){0,4})?::(?>(?2):)?)(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?>\.(?3)){3}$/iD', '0:0:0:0::0:255.255.255.255');

// Test 3
preg_match('/^(?>([a-f0-9]{1,4})(?>:(?1)){5}:|(?!(?:.*[a-f0-9]:){6,})((?1)(?>:(?1)){0,4})?::(?>(?2)!)?)(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?>\.(?3)){3}$/iD', '0:0:0:0::0!255.255.255.255');

Expected result:
----------------
// Test 1
int(1)

// Test 2
int(1)

// Test 3
int(1)

Actual result:
--------------
// Test 1
int(1)

// Test 2
int(0)

// Test 3
int(1)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-20 22:02 UTC] felipe@php.net
Not a PHP issue.
Assumption about bugs in pattern matching must be reported to http://pcre.org/

Thanks.
 [2012-05-20 22:02 UTC] felipe@php.net
-Status: Open +Status: Not a bug
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 00:01:41 2024 UTC