nlopess Wed Jan 28 22:40:37 2009 UTC
Modified files:
/php-src/ext/pcre php_pcre.c
/php-src/ext/pcre/tests bug47229.phpt preg_quote_basic.phpt
Log:
MFB: fix bug #47229: preg_quote should escape '-'
http://cvs.php.net/viewvc.cgi/php-src/ext/pcre/php_pcre.c?r1=1.245&r2=1.246&diff_format=u
Index: php-src/ext/pcre/php_pcre.c
diff -u php-src/ext/pcre/php_pcre.c:1.245 php-src/ext/pcre/php_pcre.c:1.246
--- php-src/ext/pcre/php_pcre.c:1.245 Wed Dec 31 11:12:34 2008
+++ php-src/ext/pcre/php_pcre.c Wed Jan 28 22:40:34 2009
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_pcre.c,v 1.245 2008/12/31 11:12:34 sebastian Exp $ */
+/* $Id: php_pcre.c,v 1.246 2009/01/28 22:40:34 nlopess Exp $ */
/* TODO
* php_pcre_replace_impl():
@@ -1856,6 +1856,7 @@
case '<':
case '|':
case ':':
+ case '-':
*q++ = '\\';
*q++ = c;
break;
http://cvs.php.net/viewvc.cgi/php-src/ext/pcre/tests/bug47229.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/pcre/tests/bug47229.phpt
diff -u /dev/null php-src/ext/pcre/tests/bug47229.phpt:1.2
--- /dev/null Wed Jan 28 22:40:36 2009
+++ php-src/ext/pcre/tests/bug47229.phpt Wed Jan 28 22:40:35 2009
@@ -0,0 +1,37 @@
+--TEST--
+Bug #47229 (preg_quote() doesn't escape -)
+--FILE--
+<?php
+
+var_dump(preg_quote('-oh really?'));
+
+// make sure there's no regression in matching
+preg_match('/[a\-c]+/', 'a---b', $m);
+var_dump($m);
+
+preg_match('/[a\-c]+/', 'a\-', $m);
+var_dump($m);
+
+preg_match("/a\-{2,}/", 'a----a', $m);
+var_dump($m);
+
+preg_match("/a\-{1,}/", 'a\----a', $m);
+var_dump($m);
+
+?>
+--EXPECT--
+string(13) "\-oh really\?"
+array(1) {
+ [0]=>
+ string(4) "a---"
+}
+array(1) {
+ [0]=>
+ string(1) "a"
+}
+array(1) {
+ [0]=>
+ string(5) "a----"
+}
+array(0) {
+}
http://cvs.php.net/viewvc.cgi/php-src/ext/pcre/tests/preg_quote_basic.phpt?r1=1.3&r2=1.4&diff_format=u
Index: php-src/ext/pcre/tests/preg_quote_basic.phpt
diff -u php-src/ext/pcre/tests/preg_quote_basic.phpt:1.3
php-src/ext/pcre/tests/preg_quote_basic.phpt:1.4
--- php-src/ext/pcre/tests/preg_quote_basic.phpt:1.3 Tue May 27 13:54:30 2008
+++ php-src/ext/pcre/tests/preg_quote_basic.phpt Wed Jan 28 22:40:36 2009
@@ -16,7 +16,7 @@
?>
--EXPECT--
$string_before looks like: /this *-has \ metacharacters^ in $
-$string_after looks like: \/this \*-has \\ metacharacters\^ in \$, with
metacharacters and / (set as delimiter) escaped
+$string_after looks like: \/this \*\-has \\ metacharacters\^ in \$, with
metacharacters and / (set as delimiter) escaped
int(1)
array(1) {
[0]=>
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php