]> granicus.if.org Git - php/commitdiff
MFB: fix bug #47229: preg_quote should escape '-'
authorNuno Lopes <nlopess@php.net>
Wed, 28 Jan 2009 22:40:36 +0000 (22:40 +0000)
committerNuno Lopes <nlopess@php.net>
Wed, 28 Jan 2009 22:40:36 +0000 (22:40 +0000)
ext/pcre/php_pcre.c
ext/pcre/tests/bug47229.phpt [new file with mode: 0644]
ext/pcre/tests/preg_quote_basic.phpt

index a235b6200a42ccd2c16d45ce12223d99d6f671cb..36c8fdd985de23e8ff11250f285706d334051f43 100644 (file)
@@ -1856,6 +1856,7 @@ static PHP_FUNCTION(preg_quote)
                        case '<':
                        case '|':
                        case ':':
+                       case '-':
                                *q++ = '\\';
                                *q++ = c;
                                break;
diff --git a/ext/pcre/tests/bug47229.phpt b/ext/pcre/tests/bug47229.phpt
new file mode 100644 (file)
index 0000000..74dcf20
--- /dev/null
@@ -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) {
+}
index 8349a508684c3b3754c5bdedcaf99c20f93583dc..2438b792963ffe300c931e82d548251be8557e47 100644 (file)
@@ -16,7 +16,7 @@ var_dump($matches1);
 ?>
 --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]=>