Skip to content

Commit b055a6b

Browse files
committed
tests: regex: add test with LC_COLLATE being set
While we already have a test for `p_regexec` with `LC_CTYPE` being modified, `regexec` also alters behavior as soon as `LC_COLLATE` is being modified. Most importantly, `LC_COLLATE` changes the way how ranges are interpreted to just not handling them at all. Thus, ensure that either we use `regcomp_l` to avoid this, or that we've fallen back to our builtin regex functionality which also behaves properly.
1 parent ad4ede9 commit b055a6b

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/core/posix.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,31 @@ void test_core_posix__p_regcomp_ignores_global_locale_ctype(void)
177177
cl_must_pass(error);
178178
}
179179

180+
void test_core_posix__p_regcomp_ignores_global_locale_collate(void)
181+
{
182+
regex_t preg;
183+
int error = 0;
184+
185+
const char* oldlocale = setlocale(LC_COLLATE, NULL);
186+
187+
if (!setlocale(LC_COLLATE, "UTF-8") &&
188+
!setlocale(LC_COLLATE, "c.utf8") &&
189+
!setlocale(LC_COLLATE, "en_US.UTF-8"))
190+
cl_skip();
191+
192+
if (MB_CUR_MAX == 1) {
193+
setlocale(LC_COLLATE, oldlocale);
194+
cl_fail("Expected locale to be switched to multibyte");
195+
}
196+
197+
error = p_regcomp(&preg, "[\xc0-\xff][\x80-\xbf]", REG_EXTENDED);
198+
regfree(&preg);
199+
200+
setlocale(LC_COLLATE, oldlocale);
201+
202+
cl_must_pass(error);
203+
}
204+
180205
void test_core_posix__p_regcomp_compile_userdiff_regexps(void)
181206
{
182207
size_t idx;

0 commit comments

Comments
 (0)