]> granicus.if.org Git - php/commitdiff
Fix locale switch back to C in pcre
authorNikita Popov <nikita.ppv@gmail.com>
Thu, 18 Mar 2021 09:48:43 +0000 (10:48 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Thu, 18 Mar 2021 09:48:43 +0000 (10:48 +0100)
The compile context is shared between patterns, so we need to set
the character tables unconditionally in case we switched from
a non-C locale to the C locale.

ext/pcre/php_pcre.c
ext/pcre/tests/ctype_back_to_c.phpt [new file with mode: 0644]

index 19b106997889d5062dbb36cf21e25ec586f34495..7b38ac43d749ebc292ee34d630b731192e95ad2e 100644 (file)
@@ -767,8 +767,8 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, in
                        zend_hash_add_ptr(&char_tables, _k, (void *)tables);
                        zend_string_release(_k);
                }
-               pcre2_set_character_tables(cctx, tables);
        }
+       pcre2_set_character_tables(cctx, tables);
 
        /* Set extra options for the compile context. */
        if (PHP_PCRE_DEFAULT_EXTRA_COPTIONS != extra_coptions) {
diff --git a/ext/pcre/tests/ctype_back_to_c.phpt b/ext/pcre/tests/ctype_back_to_c.phpt
new file mode 100644 (file)
index 0000000..b329091
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+Changing LC_CTYPE back to C
+--SKIPIF--
+<?php
+if (!setlocale(LC_CTYPE, "de_DE", "de-DE")) die("skip requires de_DE locale");
+?>
+--FILE--
+<?php
+var_dump(setlocale(LC_CTYPE, "de_DE", "de-DE") !== false);
+var_dump(preg_match('/\w/', "\xe4"));
+var_dump(setlocale(LC_CTYPE, "C") !== false);
+var_dump(preg_match('/\w/', "\xe4"));
+?>
+--EXPECT--
+bool(true)
+int(1)
+bool(true)
+int(0)