Bump liberty, test UTF-8 sanitization

This commit is contained in:
Přemysl Eric Janouch 2020-10-21 05:39:05 +02:00
parent 98e95de90e
commit e58ce1f02e
Signed by: p
GPG Key ID: A0420B94F92B9493
2 changed files with 15 additions and 7 deletions

View File

@ -3035,6 +3035,9 @@ irc_to_utf8 (const char *text)
{
if (!text)
return NULL;
// XXX: the validation may be unnecessarily harsh, could do with a lenient
// first pass, then replace any errors with the replacement character
size_t len = strlen (text) + 1;
if (utf8_validate (text, len))
return xstrdup (text);
@ -7940,7 +7943,7 @@ irc_sanitize_cut_off_utf8 (char **line)
const char *p = *line, *end = strchr (p, 0);
int32_t codepoint;
while ((codepoint = utf8_decode (&p, end - p)) >= 0
&& codepoint <= 0x10FFFF /* TODO: move this check into a function */)
&& utf8_validate_cp (codepoint))
;
if (codepoint != -2)
return;
@ -13984,10 +13987,15 @@ test_wrapping (void)
}
static void
test_utf8_prefix (void)
test_utf8 (void)
{
static const char *a[] = { "fřoo", "Fřooř", "fřOOŘ" };
hard_assert (utf8_common_prefix (a, N_ELEMENTS (a)) == 5);
char *cut_off = xstrdup ("ё\xD0");
irc_sanitize_cut_off_utf8 (&cut_off);
hard_assert (!strcmp (cut_off, "ё\xEF\xBF\xBD"));
free (cut_off);
}
int
@ -13995,10 +14003,10 @@ main (int argc, char *argv[])
{
struct test test;
test_init (&test, argc, argv);
test_add_simple (&test, "/config", NULL, test_config);
test_add_simple (&test, "/aliases", NULL, test_aliases);
test_add_simple (&test, "/wrapping", NULL, test_wrapping);
test_add_simple (&test, "/utf8-prefix", NULL, test_utf8_prefix);
test_add_simple (&test, "/config", NULL, test_config);
test_add_simple (&test, "/aliases", NULL, test_aliases);
test_add_simple (&test, "/wrapping", NULL, test_wrapping);
test_add_simple (&test, "/utf8", NULL, test_utf8);
return test_run (&test);
}

@ -1 +1 @@
Subproject commit 9d14562f7e81441b244dc9b2e69004ad285a5ff2
Subproject commit 53bcebc2f0bae3ba0bbcefb849bdb0ede0ea4385