mirror of
https://github.com/json-c/json-c.git
synced 2026-03-27 00:49:07 +08:00
@@ -355,6 +355,39 @@ struct incremental_step {
|
||||
{ "[1,2,3,]", -1, 7, json_tokener_error_parse_unexpected, 3 },
|
||||
{ "{\"a\":1,}", -1, 7, json_tokener_error_parse_unexpected, 3 },
|
||||
|
||||
// utf-8 test
|
||||
// acsll encoding
|
||||
{ "\x22\x31\x32\x33\x61\x73\x63\x24\x25\x26\x22",-1, -1, json_tokener_success, 5 },
|
||||
{ "\x22\x31\x32\x33\x61\x73\x63\x24\x25\x26\x22",-1, -1, json_tokener_success, 1 },
|
||||
// utf-8 encoding
|
||||
{ "\x22\xe4\xb8\x96\xe7\x95\x8c\x22",-1, -1, json_tokener_success, 5 },
|
||||
{ "\x22\xe4\xb8",-1, 3, json_tokener_error_parse_utf8_string, 4 },
|
||||
{ "\x96\xe7\x95\x8c\x22",-1, 0, json_tokener_error_parse_utf8_string, 5 },
|
||||
{ "\x22\xe4\xb8\x96\xe7\x95\x8c\x22",-1, -1, json_tokener_success, 1 },
|
||||
{ "\x22\xcf\x80\xcf\x86\x22",-1, -1, json_tokener_success, 5 },
|
||||
{ "\x22\xf0\xa5\x91\x95\x22",-1, -1, json_tokener_success, 5 },
|
||||
// wrong utf-8 encoding
|
||||
{ "\x22\xe6\x9d\x4e\x22",-1, 3, json_tokener_error_parse_utf8_string, 5 },
|
||||
{ "\x22\xe6\x9d\x4e\x22",-1, 5, json_tokener_success, 1 },
|
||||
// GBK encoding
|
||||
{ "\x22\xc0\xee\xc5\xf4\x22",-1, 2, json_tokener_error_parse_utf8_string, 5 },
|
||||
{ "\x22\xc0\xee\xc5\xf4\x22",-1, 6, json_tokener_success, 1 },
|
||||
// char after space
|
||||
{ "\x20\x20\x22\xe4\xb8\x96\x22",-1, -1, json_tokener_success, 5 },
|
||||
{ "\x20\x20\x81\x22\xe4\xb8\x96\x22",-1, 2, json_tokener_error_parse_utf8_string, 5 },
|
||||
{ "\x5b\x20\x81\x31\x5d",-1, 2, json_tokener_error_parse_utf8_string, 5 },
|
||||
// char in state inf
|
||||
{ "\x49\x6e\x66\x69\x6e\x69\x74\x79",9, 8, json_tokener_success, 1 },
|
||||
{ "\x49\x6e\x66\x81\x6e\x69\x74\x79",-1, 3, json_tokener_error_parse_utf8_string, 5 },
|
||||
// char in escape unicode
|
||||
{ "\x22\x5c\x75\x64\x38\x35\x35\x5c\x75\x64\x63\x35\x35\x22",15, 14, json_tokener_success, 5 },
|
||||
{ "\x22\x5c\x75\x64\x38\x35\x35\xc0\x75\x64\x63\x35\x35\x22",-1, 8, json_tokener_error_parse_utf8_string, 5 },
|
||||
{ "\x22\x5c\x75\x64\x30\x30\x33\x31\xc0\x22",-1, 9, json_tokener_error_parse_utf8_string, 5 },
|
||||
// char in number
|
||||
{ "\x31\x31\x81\x31\x31",-1, 2, json_tokener_error_parse_utf8_string, 5 },
|
||||
// char in object
|
||||
{ "\x7b\x22\x31\x81\x22\x3a\x31\x7d",-1, 3, json_tokener_error_parse_utf8_string, 5 },
|
||||
|
||||
{ NULL, -1, -1, json_tokener_success, 0 },
|
||||
};
|
||||
|
||||
@@ -389,9 +422,19 @@ static void test_incremental_parse()
|
||||
size_t expected_char_offset;
|
||||
|
||||
if (step->reset_tokener & 2)
|
||||
json_tokener_set_flags(tok, JSON_TOKENER_STRICT);
|
||||
{
|
||||
if (step->reset_tokener & 4)
|
||||
json_tokener_set_flags(tok, 3);
|
||||
else
|
||||
json_tokener_set_flags(tok, JSON_TOKENER_STRICT);
|
||||
}
|
||||
else
|
||||
json_tokener_set_flags(tok, 0);
|
||||
{
|
||||
if (step->reset_tokener & 4)
|
||||
json_tokener_set_flags(tok, JSON_TOKENER_VALIDATE_UTF8);
|
||||
else
|
||||
json_tokener_set_flags(tok, 0);
|
||||
}
|
||||
|
||||
if (length == -1)
|
||||
length = strlen(step->string_to_parse);
|
||||
|
||||
@@ -183,5 +183,27 @@ json_tokener_parse_ex(tok, [1,2,3,] , 8) ... OK: got object of type [array]
|
||||
json_tokener_parse_ex(tok, [1,2,,3,] , 9) ... OK: got correct error: unexpected character
|
||||
json_tokener_parse_ex(tok, [1,2,3,] , 8) ... OK: got correct error: unexpected character
|
||||
json_tokener_parse_ex(tok, {"a":1,} , 8) ... OK: got correct error: unexpected character
|
||||
End Incremental Tests OK=105 ERROR=0
|
||||
json_tokener_parse_ex(tok, "123asc$%&" , 11) ... OK: got object of type [string]: "123asc$%&"
|
||||
json_tokener_parse_ex(tok, "123asc$%&" , 11) ... OK: got object of type [string]: "123asc$%&"
|
||||
json_tokener_parse_ex(tok, "世界" , 8) ... OK: got object of type [string]: "世界"
|
||||
json_tokener_parse_ex(tok, "<22><> , 3) ... OK: got correct error: invalid utf-8 string
|
||||
json_tokener_parse_ex(tok, <20>界" , 5) ... OK: got correct error: invalid utf-8 string
|
||||
json_tokener_parse_ex(tok, "世界" , 8) ... OK: got object of type [string]: "世界"
|
||||
json_tokener_parse_ex(tok, "πφ" , 6) ... OK: got object of type [string]: "πφ"
|
||||
json_tokener_parse_ex(tok, "𥑕" , 6) ... OK: got object of type [string]: "𥑕"
|
||||
json_tokener_parse_ex(tok, "<22><>N" , 5) ... OK: got correct error: invalid utf-8 string
|
||||
json_tokener_parse_ex(tok, "<22><>N" , 5) ... OK: got object of type [string]: "<22><>N"
|
||||
json_tokener_parse_ex(tok, "<22><><EFBFBD><EFBFBD>" , 6) ... OK: got correct error: invalid utf-8 string
|
||||
json_tokener_parse_ex(tok, "<22><><EFBFBD><EFBFBD>" , 6) ... OK: got object of type [string]: "<22><><EFBFBD><EFBFBD>"
|
||||
json_tokener_parse_ex(tok, "世" , 7) ... OK: got object of type [string]: "世"
|
||||
json_tokener_parse_ex(tok, <20>"世" , 8) ... OK: got correct error: invalid utf-8 string
|
||||
json_tokener_parse_ex(tok, [ <20>1] , 5) ... OK: got correct error: invalid utf-8 string
|
||||
json_tokener_parse_ex(tok, Infinity , 9) ... OK: got object of type [double]: Infinity
|
||||
json_tokener_parse_ex(tok, Inf<6E>nity , 8) ... OK: got correct error: invalid utf-8 string
|
||||
json_tokener_parse_ex(tok, "\ud855\udc55", 15) ... OK: got object of type [string]: "𥑕"
|
||||
json_tokener_parse_ex(tok, "\ud855<35>udc55", 14) ... OK: got correct error: invalid utf-8 string
|
||||
json_tokener_parse_ex(tok, "\ud0031<33>" , 10) ... OK: got correct error: invalid utf-8 string
|
||||
json_tokener_parse_ex(tok, 11<31>11 , 5) ... OK: got correct error: invalid utf-8 string
|
||||
json_tokener_parse_ex(tok, {"1<>":1} , 8) ... OK: got correct error: invalid utf-8 string
|
||||
End Incremental Tests OK=127 ERROR=0
|
||||
==================================
|
||||
|
||||
Reference in New Issue
Block a user