From c8eb577660d2849a9289720dcd9c012f7a85a15a Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Thu, 14 Jun 2018 00:29:24 +0200 Subject: Do not damage utf8 string on escape. This fixes #492. --- tests/test-util.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'tests') diff --git a/tests/test-util.c b/tests/test-util.c index d03ac57..ad3f1cb 100644 --- a/tests/test-util.c +++ b/tests/test-util.c @@ -262,6 +262,35 @@ static void test_wildmatch_multi(void) g_assert_false(util_wildmatch("foo,?", "fo")); } +static void test_strescape(void) +{ + unsigned int i; + char *value; + struct { + char *in; + char *expected; + char *excludes; + } data[] = { + {"", "", NULL}, + {"foo", "foo", NULL}, + {"a\nb\nc", "a\\nb\\nc", NULL}, + {"foo\"bar", "foo\\bar", NULL}, + {"s\\t", "s\\\\t", NULL}, + {"u\bv", "u\\bv", NULL}, + {"w\fx", "w\\fx", NULL}, + {"y\rz", "y\\rz", NULL}, + {"tab\tdi\t", "tab\\tdi\\t", NULL}, + {"❧äüö\n@foo\t\"bar\"", "❧äüö\\n@foo\\t\\\"bar\\\"", NULL}, + {"❧äüö\n@foo\t\"bar\"", "❧äüö\\n@foo\\t\"bar\"", "\""}, + {"❧äüö\n@foo\t\"bar\"", "❧äüö\n@foo\t\\\"bar\\\"", "\n\t"}, + }; + for (i = 0; i < LENGTH(data); i++) { + value = util_strescape(data->in, data->excludes); + g_assert_cmpstr(value, ==, data->expected); + g_free(value); + } +} + int main(int argc, char *argv[]) { g_test_init(&argc, &argv, NULL); @@ -279,6 +308,7 @@ int main(int argc, char *argv[]) g_test_add_func("/test-util/wildmatch-curlybraces", test_wildmatch_curlybraces); g_test_add_func("/test-util/wildmatch-complete", test_wildmatch_complete); g_test_add_func("/test-util/wildmatch-multi", test_wildmatch_multi); + g_test_add_func("/test-util/strescape", test_strescape); return g_test_run(); } -- cgit v1.2.3