summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarkus Armbruster2018-08-23 18:39:37 +0200
committerMarkus Armbruster2018-08-24 20:26:37 +0200
commite0fe2a978e9a8c0a712afa5cfd5bc38e389ae30f (patch)
tree271653d35f785aa2c690222c50562a400be8a774 /tests
parentcheck-qjson: Streamline escaped_string()'s test strings (diff)
downloadqemu-e0fe2a978e9a8c0a712afa5cfd5bc38e389ae30f.tar.gz
qemu-e0fe2a978e9a8c0a712afa5cfd5bc38e389ae30f.tar.xz
qemu-e0fe2a978e9a8c0a712afa5cfd5bc38e389ae30f.zip
check-qjson: Cover escaped characters more thoroughly, part 2
Cover escaped single quote, surrogates, invalid escapes, and noncharacters. This demonstrates that valid surrogate pairs are misinterpreted, and invalid surrogates and noncharacters aren't rejected. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <20180823164025.12553-11-armbru@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/check-qjson.c62
1 files changed, 53 insertions, 9 deletions
diff --git a/tests/check-qjson.c b/tests/check-qjson.c
index 880453a93b..4bb4925673 100644
--- a/tests/check-qjson.c
+++ b/tests/check-qjson.c
@@ -57,10 +57,49 @@ static void escaped_string(void)
int skip;
} test_cases[] = {
{ "\\b\\f\\n\\r\\t\\\\\\\"", "\b\f\n\r\t\\\"" },
- { "\\/", "/", .skip = 1 },
+ { "\\/\\'", "/'", .skip = 1 },
{ "single byte utf-8 \\u0020", "single byte utf-8 ", .skip = 1 },
{ "double byte utf-8 \\u00A2", "double byte utf-8 \xc2\xa2" },
{ "triple byte utf-8 \\u20AC", "triple byte utf-8 \xe2\x82\xac" },
+ { "quadruple byte utf-8 \\uD834\\uDD1E", /* U+1D11E */
+ /* bug: want \xF0\x9D\x84\x9E */
+ "quadruple byte utf-8 \xED\xA0\xB4\xED\xB4\x9E", .skip = 1 },
+ { "\\", NULL },
+ { "\\z", NULL },
+ { "\\ux", NULL },
+ { "\\u1x", NULL },
+ { "\\u12x", NULL },
+ { "\\u123x", NULL },
+ { "\\u12345", "\341\210\2645" },
+ { "\\u0000x", "x", .skip = 1}, /* bug: want \xC0\x80x */
+ { "unpaired leading surrogate \\uD800",
+ /* bug: not rejected */
+ "unpaired leading surrogate \355\240\200", .skip = 1 },
+ { "unpaired leading surrogate \\uD800\\uCAFE",
+ /* bug: not rejected */
+ "unpaired leading surrogate \355\240\200\354\253\276", .skip = 1 },
+ { "unpaired leading surrogate \\uD800\\uD801\\uDC02",
+ /* bug: not rejected */
+ "unpaired leading surrogate \355\240\200\355\240\201\355\260\202",
+ .skip = 1 },
+ { "unpaired trailing surrogate \\uDC00",
+ /* bug: not rejected */
+ "unpaired trailing surrogate \355\260\200", .skip = 1},
+ { "backward surrogate pair \\uDC00\\uD800",
+ /* bug: not rejected */
+ "backward surrogate pair \355\260\200\355\240\200", .skip = 1},
+ { "noncharacter U+FDD0 \\uFDD0",
+ /* bug: not rejected */
+ "noncharacter U+FDD0 \xEF\xB7\x90", .skip = 1},
+ { "noncharacter U+FDEF \\uFDEF",
+ /* bug: not rejected */
+ "noncharacter U+FDEF \xEF\xB7\xAF", .skip = 1},
+ { "noncharacter U+1FFFE \\uD87F\\uDFFE",
+ /* bug: not rejected */
+ "noncharacter U+1FFFE \xED\xA1\xBF\xED\xBF\xBE", .skip = 1},
+ { "noncharacter U+10FFFF \\uDC3F\\uDFFF",
+ /* bug: not rejected */
+ "noncharacter U+10FFFF \xED\xB0\xBF\xED\xBF\xBF", .skip = 1},
{}
};
int i, j;
@@ -69,15 +108,20 @@ static void escaped_string(void)
for (i = 0; test_cases[i].json_in; i++) {
for (j = 0; j < 2; j++) {
- cstr = from_json_str(test_cases[i].json_in, j, &error_abort);
- g_assert_cmpstr(qstring_get_try_str(cstr),
- ==, test_cases[i].utf8_out);
- if (test_cases[i].skip == 0) {
- jstr = to_json_str(cstr);
- g_assert_cmpstr(jstr, ==, test_cases[i].json_in);
- g_free(jstr);
+ if (test_cases[i].utf8_out) {
+ cstr = from_json_str(test_cases[i].json_in, j, &error_abort);
+ g_assert_cmpstr(qstring_get_try_str(cstr),
+ ==, test_cases[i].utf8_out);
+ if (!test_cases[i].skip) {
+ jstr = to_json_str(cstr);
+ g_assert_cmpstr(jstr, ==, test_cases[i].json_in);
+ g_free(jstr);
+ }
+ qobject_unref(cstr);
+ } else {
+ cstr = from_json_str(test_cases[i].json_in, j, NULL);
+ g_assert(!cstr);
}
- qobject_unref(cstr);
}
}
}