diff --git a/degesch.c b/degesch.c index d96567f..9f03dcd 100644 --- a/degesch.c +++ b/degesch.c @@ -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); } diff --git a/liberty b/liberty index 9d14562..53bcebc 160000 --- a/liberty +++ b/liberty @@ -1 +1 @@ -Subproject commit 9d14562f7e81441b244dc9b2e69004ad285a5ff2 +Subproject commit 53bcebc2f0bae3ba0bbcefb849bdb0ede0ea4385