Bug #67235 [NEW]: Possessive quantifier problem with preg_match()
| From: | david dot a dot schmitt at verizon dot com | Date: | Thu, 08 May 2014 20:41:25 +0000 |
| Subject: | Bug #67235 [NEW]: Possessive quantifier problem with preg_match() | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-185730@lists.php.net to get a copy of this message | ||
From: david dot a dot schmitt at verizon dot com
Operating system: Linux (Fedora 20)
PHP version: 5.5.12
Package: PCRE related
Bug Type: Bug
Bug description:Possessive quantifier problem with preg_match()
Description:
------------
1. preg_match() behaviour does not match pcregrep behaviour for some
patterns involving possessive quantifiers.
2. preg_match() behaviour also appears internally inconsistent when
switching from greedy to possessive quantifiers in those cases (+ to
++).
Below is my environment (Fedora 20):
$ php -V
PHP 5.5.12 (cli) (built: May 3 2014 07:10:11)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
$ pcregrep -V
pcregrep version 8.33 2013-05-28
$ php -r "phpinfo();" | grep PCRE
PCRE (Perl Compatible Regular Expressions) Support => enabled
PCRE Library Version => 8.33 2013-05-28
Test script:
---------------
#!/bin/sh
export GREEDY='\A(?:[^"]++|"(?:[^"]*+|"")*+")+'
export POSSESSIVE="$GREEDY+"
export TEXT='NON QUOTED "QUOT""ED"'
export PATTERN
SCRIPT='
$t = getenv("TEXT");
$p = getenv("PATTERN");
preg_match("/$p/", $t, $m);
print "$m[0]\n";
'
for PATTERN in "$GREEDY" "$POSSESSIVE"
do
echo "$TEXT" | pcregrep -o -e "$PATTERN"
php -r "$SCRIPT"
done
Expected result:
----------------
NON QUOTED "QUOT""ED"
NON QUOTED "QUOT""ED"
NON QUOTED "QUOT""ED"
NON QUOTED "QUOT""ED"
Actual result:
--------------
NON QUOTED "QUOT""ED"
NON QUOTED "QUOT""ED"
NON QUOTED "QUOT""ED"
NON QUOTED
--
Edit bug report at https://bugs.php.net/bug.php?id=67235&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=67235&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=67235&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=67235&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=67235&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=67235&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=67235&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=67235&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=67235&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=67235&r=support
Expected behavior: https://bugs.php.net/fix.php?id=67235&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=67235&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=67235&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=67235&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=67235&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=67235&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=67235&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=67235&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=67235&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=67235&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=67235&r=mysqlcfg