From: Aki Tuomi Date: Thu, 19 Oct 2017 09:35:33 +0000 (+0300) Subject: test-json-parser: Update tests X-Git-Tag: 2.3.0.rc1~780 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a01faca549a403b2eda938cea0b1fb76c3ff44b6;p=thirdparty%2Fdovecot%2Fcore.git test-json-parser: Update tests Now that we actually check for valid unicode, the tests need to have valid unicode and invalid unicode in correct places. --- diff --git a/src/lib/json-parser.c b/src/lib/json-parser.c index 7a654d58f1..2dc3eacd98 100644 --- a/src/lib/json-parser.c +++ b/src/lib/json-parser.c @@ -244,7 +244,7 @@ static int json_parse_unicode_escape(struct json_parser *parser) chr = hex2dec(&parser->data[2], 4); } if (parser->data[0] != '\\' || parser->data[1] != 'u' || - UTF16_VALID_LOW_SURROGATE(chr)) { + !UTF16_VALID_LOW_SURROGATE(chr)) { parser->error = t_strdup_printf("High surrogate 0x%04x seen, " "but not followed by low surrogate", diff --git a/src/lib/test-json-parser.c b/src/lib/test-json-parser.c index f3d637ca71..975e3291c7 100644 --- a/src/lib/test-json-parser.c +++ b/src/lib/test-json-parser.c @@ -26,10 +26,11 @@ static const char json_input[] = " \"sub3\":12.456e9,\n" " \"sub4\":0.456e-789" "}," - "\"key9\": \"foo\\\\\\\"\\b\\f\\n\\r\\t\\u0001\\uffff\"," - "\"key10\": \"foo\\\\\\\"\\b\\f\\n\\r\\t\\u0001\\uffff\"," + "\"key9\": \"foo\\\\\\\"\\b\\f\\n\\r\\t\\u0001\\u10ff\"," + "\"key10\": \"foo\\\\\\\"\\b\\f\\n\\r\\t\\u0001\\u10ff\"," "\"key11\": []," - "\"key12\": [ \"foo\" , 5.24,[true],{\"aobj\":[]}]" + "\"key12\": [ \"foo\" , 5.24,[true],{\"aobj\":[]}]," + "\"key13\": \"\\ud801\\udc37\"" "}\n"; static const struct { @@ -68,9 +69,9 @@ static const struct { { JSON_TYPE_NUMBER, "0.456e-789" }, { JSON_TYPE_OBJECT_END, NULL }, { JSON_TYPE_OBJECT_KEY, "key9" }, - { JSON_TYPE_STRING, "foo\\\"\b\f\n\r\t\001\xef\xbf\xbf" }, + { JSON_TYPE_STRING, "foo\\\"\b\f\n\r\t\001\xe1\x83\xbf" }, { JSON_TYPE_OBJECT_KEY, "key10" }, - { TYPE_STREAM, "foo\\\"\b\f\n\r\t\001\xef\xbf\xbf" }, + { TYPE_STREAM, "foo\\\"\b\f\n\r\t\001\xe1\x83\xbf" }, { JSON_TYPE_OBJECT_KEY, "key11" }, { JSON_TYPE_ARRAY, NULL }, { JSON_TYPE_ARRAY_END, NULL }, @@ -86,7 +87,9 @@ static const struct { { JSON_TYPE_ARRAY, NULL }, { JSON_TYPE_ARRAY_END, NULL }, { JSON_TYPE_OBJECT_END, NULL }, - { JSON_TYPE_ARRAY_END, NULL } + { JSON_TYPE_ARRAY_END, NULL }, + { JSON_TYPE_OBJECT_KEY, "key13" }, + { JSON_TYPE_STRING, "\xf0\x90\x90\xb7" } }; static int @@ -150,6 +153,7 @@ static void test_json_parser_success(bool full_size) i_assert(pos < N_ELEMENTS(json_output)); test_assert(json_output[pos].type == type); test_assert(null_strcmp(json_output[pos].value, value) == 0); + pos++; } test_assert(ret == 0); @@ -245,7 +249,9 @@ static void test_json_parser_errors(void) "{\"foo\": [1,]}", "{\"foo\": 1,}", "{\"foo\": 1.}}", - "{\"foo\": 1},{}" + "{\"foo\": 1},{}", + "{\"foo\": \"\\ud808\"}", + "{\"foo\": \"\\udfff\"}", }; unsigned int i;