From:
Operating system: Ubuntu
PHP version: 5.3.2
Package: PCRE related
Bug Type: Bug
Bug description:PHP preg_match doesn't match string which should match
Description:
------------
This regular expression:
/^(?:[^\[\]{}']+|'[^']*')+:(?:[^\[\]{}']+|'[^']*')+$/
matches this string: a:bbbbbbbbbbbbbbb
in Perl (5.10.0-24ubuntu4):
perl <<__END__
print 'a:bbbbbbbbbbbbb' =~
q/^(?:[^\[\]{}']+|'[^']*')+:(?:[^\[\]{}']+|'[^']*')+$/;
print "\n";
__END__
1
and pcretest (libpcre3 7.8-3):
pcretest <<__END__
/^(?:[^\[\]{}']+|'[^']*')+:(?:[^\[\]{}']+|'[^']*')+$/
a:bbbbbbbbbbbbbbb
__END__
PCRE version 7.8 2008-09-05
re> data> 0: a:bbbbbbbbbbbbbbb
data>
Not, however, in PHP (5.3.2):
$ ./php --version
PHP 5.3.2 (cli) (built: Apr 25 2010 23:58:33)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
$ ./php <<__END__
<?= preg_match("/^(?:[^\[\]{}']+|'[^']*')+:(?:[^\[\]{}']+|'[^']*')+$/",
"a:bbbbbbbbbbbbb") ?>
__END__
0
The bug is pretty sensible to changes in the input. Removing a couple of
"b"s makes it match. I don't know which aspects of the regexp cause it to
fail.
For confirmation that this is indeed a bug without having to decypher the
regexp, here's proof:
<?php
$A='(?:[^\[\]{}\']+|\'[^\']*\')+';
$a= 'a';
$B=":$A";
$b= ':bbbbbbbbbbbbbbb';
print_r(preg_match("/^$A$/", "$a"));
print_r(preg_match("/^$B$/", "$b"));
print_r(preg_match("/^$A$B$/", "$a$b"));
print_r("\n");
This outputs "110", which is impossible since if /^$A$/ matches "$a" and
/^$B$/ matches "$b", /^$A$B$/ should definitely match "$a$b".
Test script:
---------------
<?= preg_match("/^(?:[^\[\]{}']+|'[^']*')+:(?:[^\[\]{}']+|'[^']*')+$/",
"a:bbbbbbbbbbbbb") ? "pass" : "fail" ?>
Expected result:
----------------
pass
Actual result:
--------------
fail
--
Edit bug report at http://bugs.php.net/bug.php?id=51663&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=51663&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=51663&r=trysnapshot53
Try a snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=51663&r=trysnapshot60
Fixed in SVN:
http://bugs.php.net/fix.php?id=51663&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=51663&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=51663&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=51663&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=51663&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=51663&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=51663&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=51663&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=51663&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=51663&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=51663&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51663&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=51663&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=51663&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=51663&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=51663&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=51663&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=51663&r=mysqlcfg