summaryrefslogtreecommitdiff
path: root/ext/pcre
diff options
context:
space:
mode:
authorNuno Lopes <nlopess@php.net>2009-01-28 22:39:33 +0000
committerNuno Lopes <nlopess@php.net>2009-01-28 22:39:33 +0000
commit4ff9ad5bf1d5fc2eb279c5b3765b6406e4b583df (patch)
treea6c73b84097df5f4a5fa4fcb2be1106681a66e7f /ext/pcre
parent458c0567b246d012c222801581283829f9692c26 (diff)
downloadphp-git-4ff9ad5bf1d5fc2eb279c5b3765b6406e4b583df.tar.gz
fix bug #47229: preg_quote should escape '-'
Diffstat (limited to 'ext/pcre')
-rw-r--r--ext/pcre/php_pcre.c1
-rw-r--r--ext/pcre/tests/bug47229.phpt37
-rw-r--r--ext/pcre/tests/preg_quote_basic.phpt2
3 files changed, 39 insertions, 1 deletions
diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c
index 0e3390f20a..496418a72e 100644
--- a/ext/pcre/php_pcre.c
+++ b/ext/pcre/php_pcre.c
@@ -1661,6 +1661,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
index 0000000000..74dcf20099
--- /dev/null
+++ b/ext/pcre/tests/bug47229.phpt
@@ -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) {
+}
diff --git a/ext/pcre/tests/preg_quote_basic.phpt b/ext/pcre/tests/preg_quote_basic.phpt
index d4bbe96616..c78f5665c0 100644
--- a/ext/pcre/tests/preg_quote_basic.phpt
+++ b/ext/pcre/tests/preg_quote_basic.phpt
@@ -17,7 +17,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]=>