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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
37 + 45 = ?
Subscribe to this entry?

 
 [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: Sat May 04 14:01:32 2024 UTC