mirror of
https://github.com/json-c/json-c.git
synced 2026-03-20 21:49:07 +08:00
Handle the \f escape sequence (the two characters: backslash followed by an f, not a literal formfeed) and extend the test_parse test to check all valid escape sequences.
This commit is contained in:
@@ -423,10 +423,12 @@ struct json_object* json_tokener_parse_ex(struct json_tokener *tok,
|
||||
case 'n':
|
||||
case 'r':
|
||||
case 't':
|
||||
case 'f':
|
||||
if(c == 'b') printbuf_memappend_fast(tok->pb, "\b", 1);
|
||||
else if(c == 'n') printbuf_memappend_fast(tok->pb, "\n", 1);
|
||||
else if(c == 'r') printbuf_memappend_fast(tok->pb, "\r", 1);
|
||||
else if(c == 't') printbuf_memappend_fast(tok->pb, "\t", 1);
|
||||
else if(c == 'f') printbuf_memappend_fast(tok->pb, "\f", 1);
|
||||
state = saved_state;
|
||||
break;
|
||||
case 'u':
|
||||
|
||||
@@ -166,6 +166,15 @@ struct incremental_step {
|
||||
/* Strings have a well defined end point, so we can stop at the quote */
|
||||
{ "\"blue\"", -1, -1, json_tokener_success, 0 },
|
||||
|
||||
/* Check each of the escape sequences defined by the spec */
|
||||
{ "\"\\\"\"", -1, -1, json_tokener_success, 0 },
|
||||
{ "\"\\\\\"", -1, -1, json_tokener_success, 0 },
|
||||
{ "\"\\b\"", -1, -1, json_tokener_success, 0 },
|
||||
{ "\"\\f\"", -1, -1, json_tokener_success, 0 },
|
||||
{ "\"\\n\"", -1, -1, json_tokener_success, 0 },
|
||||
{ "\"\\r\"", -1, -1, json_tokener_success, 0 },
|
||||
{ "\"\\t\"", -1, -1, json_tokener_success, 0 },
|
||||
|
||||
{ "[1,2,3]", -1, -1, json_tokener_success, 0 },
|
||||
|
||||
/* This behaviour doesn't entirely follow the json spec, but until we have
|
||||
@@ -190,6 +199,8 @@ static void test_incremental_parse()
|
||||
num_error = 0;
|
||||
|
||||
printf("Starting incremental tests.\n");
|
||||
printf("Note: quotes and backslashes seen in the output here are literal values passed\n");
|
||||
printf(" to the parse functions. e.g. this is 4 characters: \"\\f\"\n");
|
||||
|
||||
string_to_parse = "{ \"foo"; /* } */
|
||||
printf("json_tokener_parse(%s) ... ", string_to_parse);
|
||||
|
||||
@@ -21,6 +21,8 @@ new_obj.to_string()={ "abc": 12, "foo": "bar", "bool0": false, "bool1": true, "a
|
||||
json_tokener_parse_versbose() OK
|
||||
==================================
|
||||
Starting incremental tests.
|
||||
Note: quotes and backslashes seen in the output here are literal values passed
|
||||
to the parse functions. e.g. this is 4 characters: "\f"
|
||||
json_tokener_parse({ "foo) ... got error as expected
|
||||
json_tokener_parse_ex(tok, { "foo": 123 }, 14) ... OK: got object of type [object]: { "foo": 123 }
|
||||
json_tokener_parse_ex(tok, { "foo": 456 }, 14) ... OK: got object of type [object]: { "foo": 456 }
|
||||
@@ -39,8 +41,15 @@ json_tokener_parse_ex(tok, "Y" , 3) ... OK: got object of type [string
|
||||
json_tokener_parse_ex(tok, 1 , 1) ... OK: got correct error: continue
|
||||
json_tokener_parse_ex(tok, 2 , 2) ... OK: got object of type [int]: 12
|
||||
json_tokener_parse_ex(tok, "blue" , 6) ... OK: got object of type [string]: "blue"
|
||||
json_tokener_parse_ex(tok, "\"" , 4) ... OK: got object of type [string]: "\""
|
||||
json_tokener_parse_ex(tok, "\\" , 4) ... OK: got object of type [string]: "\\"
|
||||
json_tokener_parse_ex(tok, "\b" , 4) ... OK: got object of type [string]: "\b"
|
||||
json_tokener_parse_ex(tok, "\f" , 4) ... OK: got object of type [string]: "\u000c"
|
||||
json_tokener_parse_ex(tok, "\n" , 4) ... OK: got object of type [string]: "\n"
|
||||
json_tokener_parse_ex(tok, "\r" , 4) ... OK: got object of type [string]: "\r"
|
||||
json_tokener_parse_ex(tok, "\t" , 4) ... OK: got object of type [string]: "\t"
|
||||
json_tokener_parse_ex(tok, [1,2,3] , 7) ... OK: got object of type [array]: [ 1, 2, 3 ]
|
||||
json_tokener_parse_ex(tok, [1,2,3,] , 8) ... OK: got object of type [array]: [ 1, 2, 3 ]
|
||||
json_tokener_parse_ex(tok, [1,2,,3,] , 9) ... OK: got correct error: unexpected character
|
||||
End Incremental Tests OK=20 ERROR=0
|
||||
End Incremental Tests OK=27 ERROR=0
|
||||
==================================
|
||||
|
||||
Reference in New Issue
Block a user