From 536326bacfacb268fe7445073cc61ef116b1de35 Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Wed, 28 Jan 2009 22:40:36 +0000 Subject: [PATCH] MFB: fix bug #47229: preg_quote should escape '-' --- ext/pcre/php_pcre.c | 1 + ext/pcre/tests/bug47229.phpt | 37 ++++++++++++++++++++++++++++ ext/pcre/tests/preg_quote_basic.phpt | 2 +- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 ext/pcre/tests/bug47229.phpt diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index a235b6200a..36c8fdd985 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -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 index 0000000000..74dcf20099 --- /dev/null +++ b/ext/pcre/tests/bug47229.phpt @@ -0,0 +1,37 @@ +--TEST-- +Bug #47229 (preg_quote() doesn't escape -) +--FILE-- + +--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 8349a50868..2438b79296 100644 --- a/ext/pcre/tests/preg_quote_basic.phpt +++ b/ext/pcre/tests/preg_quote_basic.phpt @@ -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]=> -- 2.40.0