Skip to content

Commit

Permalink
Merge pull request #94 from pt300/master
Browse files Browse the repository at this point in the history
Fix for no error with unmatched closing bracket with PARENT_LINKS
  • Loading branch information
zserge committed Oct 12, 2016
2 parents 0f574ea + c3131d0 commit 1682c32
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions jsmn.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ int jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
break;
}
if (token->parent == -1) {
if(token->type != type || parser->toksuper == -1) {
return JSMN_ERROR_INVAL;
}
break;
}
token = &tokens[token->parent];
Expand Down
20 changes: 20 additions & 0 deletions test/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,25 @@ int test_nonstrict(void) {
return 0;
}

int test_unmatched_brackets(void) {
const char *js;
js = "\"key 1\": 1234}";
check(parse(js, JSMN_ERROR_INVAL, 2));
js = "{\"key 1\": 1234";
check(parse(js, JSMN_ERROR_PART, 3));
js = "{\"key 1\": 1234}}";
check(parse(js, JSMN_ERROR_INVAL, 3));
js = "\"key 1\"}: 1234";
check(parse(js, JSMN_ERROR_INVAL, 3));
js = "\"key {1\": 1234";
check(parse(js, 2, 2,
JSMN_STRING, "key {1", 1,
JSMN_PRIMITIVE, "1234"));
js = "{{\"key 1\": 1234}";
check(parse(js, JSMN_ERROR_PART, 4));
return 0;
}

int main(void) {
test(test_empty, "test for a empty JSON objects/arrays");
test(test_object, "test for a JSON objects");
Expand All @@ -373,6 +392,7 @@ int main(void) {
test(test_issue_27, "test issue #27");
test(test_count, "test tokens count estimation");
test(test_nonstrict, "test for non-strict mode");
test(test_unmatched_brackets, "test for unmatched brackets");
printf("\nPASSED: %d\nFAILED: %d\n", test_passed, test_failed);
return (test_failed > 0);
}

0 comments on commit 1682c32

Please sign in to comment.