aboutsummaryrefslogtreecommitdiff
path: root/degesch.c
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2020-10-21 05:39:05 +0200
committerPřemysl Eric Janouch <p@janouch.name>2020-10-21 05:44:27 +0200
commite58ce1f02ebd24284c1c2ba0a455cd6a23107b19 (patch)
tree92ebdb3a9b9d0e3511ba309340e150d399b8a4e1 /degesch.c
parent98e95de90e79c581d2296084ea23919ed616ad29 (diff)
downloadxK-e58ce1f02ebd24284c1c2ba0a455cd6a23107b19.tar.gz
xK-e58ce1f02ebd24284c1c2ba0a455cd6a23107b19.tar.xz
xK-e58ce1f02ebd24284c1c2ba0a455cd6a23107b19.zip
Bump liberty, test UTF-8 sanitization
Diffstat (limited to 'degesch.c')
-rw-r--r--degesch.c20
1 files changed, 14 insertions, 6 deletions
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);
}