From: Andreas dot Klauer at metamorpher dot de
Operating system:
PHP version: 5.3.15
Package: PCRE related
Bug Type: Bug
Bug description:Impossible to escape/match delimiters within \Q \E
Description:
------------
PCRE allows literal matches of strings between \Q and \E. This is also
documented, \Q.$.\E will match literal .$.
However, if that literal string contains the regexp delimiter (/ or # or ~
or () or whichever you choose), the regexp compile either fails, or the
match fails because it tries to match the escape char used to escape the
delimiter.
The problem is php_pcre::pcre_get_compiled_regex_cache() which parses the
delimiter, not taking \Q \E in account. Delimiters between \Q \E should be
treated as literal characters, not delimiters (that's what Perl does); or
alternatively if delimiters have to be escaped, the escape char should be
removed from the pattern.
Workaround: Use preg_quote() instead of \Q \E if there's a chance the
delimiter may appear within \Q \E
Test script:
---------------
preg_replace("/\Q/#~\E/", ...);
=> Warning: preg_replace(): Unknown modifier '#' in php shell code on line
1
preg_replace("/\Q\/#~\E/", "OK", "/#~");
=> "/#~" (expected "OK")
preg_replace("/\Q\/#~\E/", "FAIL", "\/#~")
=> "FAIL" (expected "\/#~");
--
Edit bug report at https://bugs.php.net/bug.php?id=62646&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=62646&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=62646&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=62646&r=trysnapshottrunk
Fixed in SVN:
https://bugs.php.net/fix.php?id=62646&r=fixed
Fixed in SVN and need be documented:
https://bugs.php.net/fix.php?id=62646&r=needdocs
Fixed in release:
https://bugs.php.net/fix.php?id=62646&r=alreadyfixed
Need backtrace:
https://bugs.php.net/fix.php?id=62646&r=needtrace
Need Reproduce Script:
https://bugs.php.net/fix.php?id=62646&r=needscript
Try newer version:
https://bugs.php.net/fix.php?id=62646&r=oldversion
Not developer issue:
https://bugs.php.net/fix.php?id=62646&r=support
Expected behavior:
https://bugs.php.net/fix.php?id=62646&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=62646&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=62646&r=submittedtwice
register_globals:
https://bugs.php.net/fix.php?id=62646&r=globals
PHP 4 support discontinued:
https://bugs.php.net/fix.php?id=62646&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=62646&r=dst
IIS Stability:
https://bugs.php.net/fix.php?id=62646&r=isapi
Install GNU Sed:
https://bugs.php.net/fix.php?id=62646&r=gnused
Floating point limitations:
https://bugs.php.net/fix.php?id=62646&r=float
No Zend Extensions:
https://bugs.php.net/fix.php?id=62646&r=nozend
MySQL Configuration Error:
https://bugs.php.net/fix.php?id=62646&r=mysqlcfg