Skip to content

Commit

Permalink
Fix {"a":[1,2]} case
Browse files Browse the repository at this point in the history
  • Loading branch information
themobiusproject committed Sep 8, 2020
1 parent fe07a15 commit 9f7e9de
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions jsmn.h
Original file line number Diff line number Diff line change
Expand Up @@ -908,11 +908,11 @@ jsmnint_t jsmn_parse_comma(jsmn_parser *parser, jsmntok_t *tokens)
return JSMN_ERROR_INVAL;
}

jsmntype_t type = JSMN_UNDEFINED;
jsmntype_t type = JSMN_UNDEFINED; /*!< parent's type */
if (tokens == NULL) {
if (parser->toksuper < (sizeof(jsmnint_t) * CHAR_BIT) &&
parser->toknext & (1 << parser->toksuper)) {
type = JSMN_INSD_OBJ;
type = JSMN_OBJECT;
}
} else {
if (parser->toksuper != JSMN_NEG) {
Expand All @@ -921,7 +921,7 @@ jsmnint_t jsmn_parse_comma(jsmn_parser *parser, jsmntok_t *tokens)
}

if (parser->toksuper != JSMN_NEG) {
if (type & (JSMN_OBJECT | JSMN_INSD_OBJ)) {
if (type & JSMN_OBJECT) {
parser->expected = JSMN_AFTR_COMMA_O;
} else {
parser->expected = JSMN_AFTR_COMMA_A;
Expand Down
2 changes: 2 additions & 0 deletions test/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -1403,6 +1403,8 @@ int test_object(void) {
JSMN_PRIMITIVE, "0"));
check(parse("{\"a\":[]}", 3, 3, JSMN_OBJECT, 0, 8, 1, JSMN_STRING, "a", 1,
JSMN_ARRAY, 5, 7, 0));
check(parse("{\"a\":[1,2]}", 5, 5, JSMN_OBJECT, 0, 11, 1, JSMN_STRING, "a", 1,
JSMN_ARRAY, 5, 10, 2, JSMN_PRIMITIVE, "1", JSMN_PRIMITIVE, "2"));
check(parse("{\"a\":{},\"b\":{}}", 5, 5, JSMN_OBJECT, -1, -1, 2, JSMN_STRING,
"a", 1, JSMN_OBJECT, -1, -1, 0, JSMN_STRING, "b", 1, JSMN_OBJECT,
-1, -1, 0));
Expand Down

0 comments on commit 9f7e9de

Please sign in to comment.