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
 [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

Pull Requests

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: Sun Dec 15 20:01:27 2024 UTC