mirror of
https://github.com/json-c/json-c.git
synced 2026-03-30 02:19:06 +08:00
Fix incremental parsing of invalid numbers with exponents, such as "0e+-" and "12.3E12E12", while still allowing "0e+" in non-strict mode.
Deprecate the json_parse_double() function from json_util.h
This commit is contained in:
@@ -343,9 +343,34 @@ struct incremental_step
|
||||
/* This should parse as the number 12, since it continues the "1" */
|
||||
{"2", 2, 1, json_tokener_success, 0},
|
||||
{"12{", 3, 2, json_tokener_success, 1},
|
||||
/* Parse number in strict model */
|
||||
/* Parse number in strict mode */
|
||||
{"[02]", -1, 3, json_tokener_error_parse_number, 1, JSON_TOKENER_STRICT},
|
||||
|
||||
{"0e+0", 5, 4, json_tokener_success, 1},
|
||||
{"[0e+0]", -1, -1, json_tokener_success, 1},
|
||||
|
||||
/* The behavior when missing the exponent varies slightly */
|
||||
{"0e", 2, 2, json_tokener_continue, 1},
|
||||
{"0e", 3, 2, json_tokener_success, 1},
|
||||
{"0e", 3, 2, json_tokener_error_parse_eof, 1, JSON_TOKENER_STRICT},
|
||||
{"[0e]", -1, -1, json_tokener_success, 1},
|
||||
{"[0e]", -1, 3, json_tokener_error_parse_number, 1, JSON_TOKENER_STRICT},
|
||||
|
||||
{"0e+", 3, 3, json_tokener_continue, 1},
|
||||
{"0e+", 4, 3, json_tokener_success, 1},
|
||||
{"0e+", 4, 3, json_tokener_error_parse_eof, 1, JSON_TOKENER_STRICT},
|
||||
{"[0e+]", -1, -1, json_tokener_success, 1},
|
||||
{"[0e+]", -1, 4, json_tokener_error_parse_number, 1, JSON_TOKENER_STRICT},
|
||||
|
||||
{"0e-", 3, 3, json_tokener_continue, 1},
|
||||
{"0e-", 4, 3, json_tokener_success, 1},
|
||||
{"0e-", 4, 3, json_tokener_error_parse_eof, 1, JSON_TOKENER_STRICT},
|
||||
{"[0e-]", -1, -1, json_tokener_success, 1},
|
||||
{"[0e-]", -1, 4, json_tokener_error_parse_number, 1, JSON_TOKENER_STRICT},
|
||||
|
||||
{"0e+-", 5, 3, json_tokener_error_parse_number, 1},
|
||||
{"[0e+-]", -1, 4, json_tokener_error_parse_number, 1},
|
||||
|
||||
/* Similar tests for other kinds of objects: */
|
||||
/* These could all return success immediately, since regardless of
|
||||
what follows the false/true/null token we *will* return a json object,
|
||||
|
||||
@@ -145,6 +145,25 @@ json_tokener_parse_ex(tok, 1 , 1) ... OK: got correct error: continu
|
||||
json_tokener_parse_ex(tok, 2 , 2) ... OK: got object of type [int]: 12
|
||||
json_tokener_parse_ex(tok, 12{ , 3) ... OK: got object of type [int]: 12
|
||||
json_tokener_parse_ex(tok, [02] , 4) ... OK: got correct error: number expected
|
||||
json_tokener_parse_ex(tok, 0e+0 , 5) ... OK: got object of type [double]: 0e+0
|
||||
json_tokener_parse_ex(tok, [0e+0] , 6) ... OK: got object of type [array]: [ 0e+0 ]
|
||||
json_tokener_parse_ex(tok, 0e , 2) ... OK: got correct error: continue
|
||||
json_tokener_parse_ex(tok, 0e , 3) ... OK: got object of type [double]: 0
|
||||
json_tokener_parse_ex(tok, 0e , 3) ... OK: got correct error: unexpected end of data
|
||||
json_tokener_parse_ex(tok, [0e] , 4) ... OK: got object of type [array]: [ 0 ]
|
||||
json_tokener_parse_ex(tok, [0e] , 4) ... OK: got correct error: number expected
|
||||
json_tokener_parse_ex(tok, 0e+ , 3) ... OK: got correct error: continue
|
||||
json_tokener_parse_ex(tok, 0e+ , 4) ... OK: got object of type [double]: 0
|
||||
json_tokener_parse_ex(tok, 0e+ , 4) ... OK: got correct error: unexpected end of data
|
||||
json_tokener_parse_ex(tok, [0e+] , 5) ... OK: got object of type [array]: [ 0 ]
|
||||
json_tokener_parse_ex(tok, [0e+] , 5) ... OK: got correct error: number expected
|
||||
json_tokener_parse_ex(tok, 0e- , 3) ... OK: got correct error: continue
|
||||
json_tokener_parse_ex(tok, 0e- , 4) ... OK: got object of type [double]: 0
|
||||
json_tokener_parse_ex(tok, 0e- , 4) ... OK: got correct error: unexpected end of data
|
||||
json_tokener_parse_ex(tok, [0e-] , 5) ... OK: got object of type [array]: [ 0 ]
|
||||
json_tokener_parse_ex(tok, [0e-] , 5) ... OK: got correct error: number expected
|
||||
json_tokener_parse_ex(tok, 0e+- , 5) ... OK: got correct error: number expected
|
||||
json_tokener_parse_ex(tok, [0e+-] , 6) ... OK: got correct error: number expected
|
||||
json_tokener_parse_ex(tok, false , 5) ... OK: got correct error: continue
|
||||
json_tokener_parse_ex(tok, false , 6) ... OK: got object of type [boolean]: false
|
||||
json_tokener_parse_ex(tok, true , 4) ... OK: got correct error: continue
|
||||
@@ -246,5 +265,5 @@ json_tokener_parse_ex(tok, "\ud855
|
||||
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=160 ERROR=0
|
||||
End Incremental Tests OK=179 ERROR=0
|
||||
==================================
|
||||
|
||||
Reference in New Issue
Block a user