mirror of
https://github.com/json-c/json-c.git
synced 2026-04-11 08:19:08 +08:00
Fix parsing of "-Infinity" when the "-" and "Infinity" are split across multiple calls.
Add several additional test cases for partial parsing of infinity values.
This commit is contained in:
@@ -763,7 +763,7 @@ struct json_object* json_tokener_parse_ex(struct json_tokener *tok,
|
|||||||
printbuf_memappend_fast(tok->pb, case_start, case_len);
|
printbuf_memappend_fast(tok->pb, case_start, case_len);
|
||||||
|
|
||||||
// Check for -Infinity
|
// Check for -Infinity
|
||||||
if (tok->pb->buf[0] == '-' && case_len == 1 &&
|
if (tok->pb->buf[0] == '-' && case_len <= 1 &&
|
||||||
(c == 'i' || c == 'I'))
|
(c == 'i' || c == 'I'))
|
||||||
{
|
{
|
||||||
state = json_tokener_state_inf;
|
state = json_tokener_state_inf;
|
||||||
|
|||||||
@@ -197,6 +197,40 @@ struct incremental_step {
|
|||||||
{ "null", 4, 4, json_tokener_continue, 1 },
|
{ "null", 4, 4, json_tokener_continue, 1 },
|
||||||
{ "null", 5, 4, json_tokener_success, 1 },
|
{ "null", 5, 4, json_tokener_success, 1 },
|
||||||
|
|
||||||
|
{ "Infinity", 9, 8, json_tokener_success, 1 },
|
||||||
|
{ "infinity", 9, 8, json_tokener_success, 1 },
|
||||||
|
{ "-infinity", 10, 9, json_tokener_success, 1 },
|
||||||
|
{ "infinity", 9, 0, json_tokener_error_parse_unexpected, 3 },
|
||||||
|
{ "-infinity", 10, 1, json_tokener_error_parse_unexpected, 3 },
|
||||||
|
|
||||||
|
{ "inf", 3, 3, json_tokener_continue, 0 },
|
||||||
|
{ "inity", 6, 5, json_tokener_success, 1 },
|
||||||
|
{ "-inf", 4, 4, json_tokener_continue, 0 },
|
||||||
|
{ "inity", 6, 5, json_tokener_success, 1 },
|
||||||
|
|
||||||
|
{ "i", 1, 1, json_tokener_continue, 0 },
|
||||||
|
{ "n", 1, 1, json_tokener_continue, 0 },
|
||||||
|
{ "f", 1, 1, json_tokener_continue, 0 },
|
||||||
|
{ "i", 1, 1, json_tokener_continue, 0 },
|
||||||
|
{ "n", 1, 1, json_tokener_continue, 0 },
|
||||||
|
{ "i", 1, 1, json_tokener_continue, 0 },
|
||||||
|
{ "t", 1, 1, json_tokener_continue, 0 },
|
||||||
|
{ "y", 1, 1, json_tokener_continue, 0 },
|
||||||
|
{ "", 1, 0, json_tokener_success, 1 },
|
||||||
|
|
||||||
|
{ "-", 1, 1, json_tokener_continue, 0 },
|
||||||
|
{ "inf", 3, 3, json_tokener_continue, 0 },
|
||||||
|
{ "ini", 3, 3, json_tokener_continue, 0 },
|
||||||
|
{ "ty", 3, 2, json_tokener_success, 1 },
|
||||||
|
|
||||||
|
{ "-", 1, 1, json_tokener_continue, 0 },
|
||||||
|
{ "i", 1, 1, json_tokener_continue, 0 },
|
||||||
|
{ "nfini", 5, 5, json_tokener_continue, 0 },
|
||||||
|
{ "ty", 3, 2, json_tokener_success, 1 },
|
||||||
|
|
||||||
|
{ "-i", 2, 2, json_tokener_continue, 0 },
|
||||||
|
{ "nfinity", 8, 7, json_tokener_success, 1 },
|
||||||
|
|
||||||
/* offset=1 because "n" is the start of "null". hmm... */
|
/* offset=1 because "n" is the start of "null". hmm... */
|
||||||
{ "noodle", 7, 1, json_tokener_error_parse_null, 1 },
|
{ "noodle", 7, 1, json_tokener_error_parse_null, 1 },
|
||||||
/* offset=2 because "na" is the start of "nan". hmm... */
|
/* offset=2 because "na" is the start of "nan". hmm... */
|
||||||
|
|||||||
Reference in New Issue
Block a user