Skip to content

Commit 4be867e

Browse files
committed
Fix locale switch back to C in pcre
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.
1 parent a08847a commit 4be867e

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

ext/pcre/php_pcre.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,8 +767,8 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, in
767767
zend_hash_add_ptr(&char_tables, _k, (void *)tables);
768768
zend_string_release(_k);
769769
}
770-
pcre2_set_character_tables(cctx, tables);
771770
}
771+
pcre2_set_character_tables(cctx, tables);
772772

773773
/* Set extra options for the compile context. */
774774
if (PHP_PCRE_DEFAULT_EXTRA_COPTIONS != extra_coptions) {

ext/pcre/tests/ctype_back_to_c.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Changing LC_CTYPE back to C
3+
--SKIPIF--
4+
<?php
5+
if (!setlocale(LC_CTYPE, "de_DE", "de-DE")) die("skip requires de_DE locale");
6+
?>
7+
--FILE--
8+
<?php
9+
var_dump(setlocale(LC_CTYPE, "de_DE", "de-DE") !== false);
10+
var_dump(preg_match('/\w/', "\xe4"));
11+
var_dump(setlocale(LC_CTYPE, "C") !== false);
12+
var_dump(preg_match('/\w/', "\xe4"));
13+
?>
14+
--EXPECT--
15+
bool(true)
16+
int(1)
17+
bool(true)
18+
int(0)

0 commit comments

Comments
 (0)