From 090a9b33316a448f1af9ba865484fa5dafeda4a7 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sun, 3 Oct 2010 16:01:38 +0000 Subject: [PATCH] - Fixed bug #52971 (PCRE-Meta-Characters not working with utf-8) # In PCRE, by default, \d, \D, \s, \S, \w, and \W recognize only ASCII # characters, even in UTF-8 mode. However, this can be changed by setting # the PCRE_UCP option. --- NEWS | 1 + ext/pcre/php_pcre.c | 9 +++++++- ext/pcre/tests/bug52971.phpt | 43 ++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 ext/pcre/tests/bug52971.phpt diff --git a/NEWS b/NEWS index bcd560c8db9..9e47361f747 100644 --- a/NEWS +++ b/NEWS @@ -22,6 +22,7 @@ - Fixed possible crash in mssql_fetch_batch(). (Kalle) - Fixed inconsistent backlog default value (-1) in FPM on many systems. (fat) +- Fixed bug #52971 (PCRE-Meta-Characters not working with utf-8). (Felipe) - Fixed bug #52947 (segfault when ssl stream option capture_peer_cert_chain used). (Felipe) - Fixed bug #52944 (Invalid write on second and subsequent reads with an diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index dcbc98fb851..ccb0a51c0ec 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -350,7 +350,14 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(char *regex, int regex_le case 'S': do_study = 1; break; case 'U': coptions |= PCRE_UNGREEDY; break; case 'X': coptions |= PCRE_EXTRA; break; - case 'u': coptions |= PCRE_UTF8; break; + case 'u': coptions |= PCRE_UTF8; + /* In PCRE, by default, \d, \D, \s, \S, \w, and \W recognize only ASCII + characters, even in UTF-8 mode. However, this can be changed by setting + the PCRE_UCP option. */ +#ifdef PCRE_UCP + coptions |= PCRE_UCP; +#endif + break; /* Custom preg options */ case 'e': poptions |= PREG_REPLACE_EVAL; break; diff --git a/ext/pcre/tests/bug52971.phpt b/ext/pcre/tests/bug52971.phpt new file mode 100644 index 00000000000..5949cb220c3 --- /dev/null +++ b/ext/pcre/tests/bug52971.phpt @@ -0,0 +1,43 @@ +--TEST-- +Bug #52971 (PCRE-Meta-Characters not working with utf-8) +--SKIPIF-- += 8.1 is required!'); ?> +--FILE-- + +--EXPECTF-- +array(1) { + [0]=> + array(1) { + [0]=> + array(2) { + [0]=> + string(6) "Wasser" + [1]=> + int(61) + } + } +} +array(1) { + [0]=> + array(1) { + [0]=> + array(2) { + [0]=> + string(7) " Wasser" + [1]=> + int(60) + } + } +}