mirror of
https://github.com/json-c/json-c.git
synced 2026-09-07 16:46:50 +08:00
Check the whole RFC 8259 number grammar in strict mode
Strict mode rejected leading zeros but nothing else about the shape of a
number, so several malformed numbers parsed and were then written back out
verbatim, producing JSON that other parsers reject:
$ echo '[2.e3]' | ./json_parse -s -
[ 2.e3 ]
RFC 8259 requires a mandatory integer part and at least one digit in both the
fraction and the exponent:
number = [ minus ] int [ frac ] [ exp ]
int = zero / ( digit1-9 *DIGIT )
frac = decimal-point 1*DIGIT
exp = e [ minus / plus ] 1*DIGIT
so "1.", "-2.", "2.e3", "2.e+3", "0.e1", "-.123", "1e" and "1e+" are all
invalid. Walk the accumulated text against that grammar instead. The leading
zero rule from the previous check is part of the same walk rather than a
separate test, and its cases keep their coverage.
Only JSON_TOKENER_STRICT is affected; the default tokener stays as lenient as
it was. Measured against JSONTestSuite (318 files): strict mode went from 44
to 37 files accepted that the suite says must be rejected, default mode stayed
at 71, and nothing that must be accepted regressed in either mode.
This commit is contained in:
@@ -163,6 +163,19 @@ json_tokener_parse_ex(tok, [-0123] , 7) ... OK: got correct error: number
|
||||
json_tokener_parse_ex(tok, [01.5] , 6) ... OK: got correct error: number expected
|
||||
json_tokener_parse_ex(tok, [-0] , 4) ... OK: got object of type [array]: [ 0 ]
|
||||
json_tokener_parse_ex(tok, [0.5] , 5) ... OK: got object of type [array]: [ 0.5 ]
|
||||
json_tokener_parse_ex(tok, [1.] , 4) ... OK: got correct error: number expected
|
||||
json_tokener_parse_ex(tok, [-2.] , 5) ... OK: got correct error: number expected
|
||||
json_tokener_parse_ex(tok, [2.e3] , 6) ... OK: got correct error: number expected
|
||||
json_tokener_parse_ex(tok, [2.e+3] , 7) ... OK: got correct error: number expected
|
||||
json_tokener_parse_ex(tok, [0.e1] , 6) ... OK: got correct error: number expected
|
||||
json_tokener_parse_ex(tok, [1e] , 4) ... OK: got correct error: number expected
|
||||
json_tokener_parse_ex(tok, [1e+] , 5) ... OK: got correct error: number expected
|
||||
json_tokener_parse_ex(tok, [-.123] , 7) ... OK: got correct error: number expected
|
||||
json_tokener_parse_ex(tok, [1.0] , 5) ... OK: got object of type [array]: [ 1.0 ]
|
||||
json_tokener_parse_ex(tok, [2e3] , 5) ... OK: got object of type [array]: [ 2e3 ]
|
||||
json_tokener_parse_ex(tok, [2E-3] , 6) ... OK: got object of type [array]: [ 2E-3 ]
|
||||
json_tokener_parse_ex(tok, [0.123] , 7) ... OK: got object of type [array]: [ 0.123 ]
|
||||
json_tokener_parse_ex(tok, [-0.123] , 8) ... OK: got object of type [array]: [ -0.123 ]
|
||||
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
|
||||
@@ -375,5 +388,5 @@ json_tokener_parse_ex(tok, {"":1} , 7) ... OK: got correct error: invalid
|
||||
json_tokener_parse_ex(tok, {"":1} , 7) ... OK: got correct error: invalid string sequence
|
||||
json_tokener_parse_ex(tok, {"":1} , 7) ... OK: got correct error: invalid string sequence
|
||||
json_tokener_parse_ex(tok, {"":1} , 7) ... OK: got correct error: invalid string sequence
|
||||
End Incremental Tests OK=279 ERROR=0
|
||||
End Incremental Tests OK=292 ERROR=0
|
||||
==================================
|
||||
|
||||
Reference in New Issue
Block a user