From 437526675a3c72eb0d86d7f5b834fb061c977de2 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Sun, 26 Jul 2020 23:04:37 +0100 Subject: [PATCH 1/3] tests: Test that UTF-8 is escaped correctly by g_strescape() `g_strescape()` is documented as escaping UTF-8 characters, so test that it does. Signed-off-by: Philip Withnall Fixes: #4 --- glib/tests/strfuncs.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/glib/tests/strfuncs.c b/glib/tests/strfuncs.c index e1f9619c7..14b4d6c05 100644 --- a/glib/tests/strfuncs.c +++ b/glib/tests/strfuncs.c @@ -731,6 +731,16 @@ test_strcompress_strescape (void) g_assert_cmpstr (str, ==, "abc\\\"\b\f\n\r\t\v\003\177\234\313"); g_free (str); g_free (tmp); + + /* Unicode round trip */ + str = g_strescape ("héllø there⸘", NULL); + g_assert_nonnull (str); + g_assert_cmpstr (str, ==, "h\\303\\251ll\\303\\270 there\\342\\270\\230"); + tmp = g_strcompress (str); + g_assert_nonnull (tmp); + g_assert_cmpstr (tmp, ==, "héllø there⸘"); + g_free (tmp); + g_free (str); } /* Testing g_ascii_strcasecmp() and g_ascii_strncasecmp() */ From 59eb3c5bdb52697fec1559ca6113e8c30062770e Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Sun, 26 Jul 2020 23:05:31 +0100 Subject: [PATCH 2/3] tests: Add missing cast to URI tests This fixes a compiler warning. Signed-off-by: Philip Withnall --- glib/tests/uri.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glib/tests/uri.c b/glib/tests/uri.c index 01ca68c26..70cee76e9 100644 --- a/glib/tests/uri.c +++ b/glib/tests/uri.c @@ -382,7 +382,7 @@ test_uri_unescape_bytes (gconstpointer test_data) tests[] = { { "%00%00", NULL, 2, (const guint8 *) "\x00\x00" }, - { "/cursors/none.png", "/", 17, "/cursors/none.png" }, + { "/cursors/none.png", "/", 17, (const guint8 *) "/cursors/none.png" }, { "/cursors%2fbad-subdir/none.png", "/", -1, NULL }, { "%%", NULL, -1, NULL }, { "%", NULL, -1, NULL }, From 1ef6e84012387866eea21ba55a9c5bf2bee2d35f Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Sun, 26 Jul 2020 23:22:06 +0100 Subject: [PATCH 3/3] tests: Add some tests for expanding invalid escapes with g_strcompress() This brings the branch coverage of `g_strcompress()` up to 100%. Yay. Signed-off-by: Philip Withnall --- glib/tests/strfuncs.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/glib/tests/strfuncs.c b/glib/tests/strfuncs.c index 14b4d6c05..ea87c7d1e 100644 --- a/glib/tests/strfuncs.c +++ b/glib/tests/strfuncs.c @@ -741,6 +741,12 @@ test_strcompress_strescape (void) g_assert_cmpstr (tmp, ==, "héllø there⸘"); g_free (tmp); g_free (str); + + /* Test expanding invalid escapes */ + str = g_strcompress ("\\11/ \\118 \\8aa \\19"); + g_assert_nonnull (str); + g_assert_cmpstr (str, ==, "\t/ \t8 8aa \0019"); + g_free (str); } /* Testing g_ascii_strcasecmp() and g_ascii_strncasecmp() */