Skip to content

Commit 02aa6f0

Browse files
committed
Merge pull request #94 from remicollet/issue-strict2
more strictness
2 parents 8356ecc + 4039f91 commit 02aa6f0

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

json_tokener.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ struct json_object* json_tokener_parse_ex(struct json_tokener *tok,
265265
if ((!ADVANCE_CHAR(str, tok)) || (!PEEK_CHAR(c, tok)))
266266
goto out;
267267
}
268-
if(c == '/') {
268+
if(c == '/' && !(tok->flags & JSON_TOKENER_STRICT)) {
269269
printbuf_reset(tok->pb);
270270
printbuf_memappend_fast(tok->pb, &c, 1);
271271
state = json_tokener_state_comment_start;
@@ -293,8 +293,13 @@ struct json_object* json_tokener_parse_ex(struct json_tokener *tok,
293293
printbuf_reset(tok->pb);
294294
tok->st_pos = 0;
295295
goto redo_char;
296-
case '"':
297296
case '\'':
297+
if (tok->flags & JSON_TOKENER_STRICT) {
298+
/* in STRICT mode only double-quote are allowed */
299+
tok->err = json_tokener_error_parse_unexpected;
300+
goto out;
301+
}
302+
case '"':
298303
state = json_tokener_state_string;
299304
printbuf_reset(tok->pb);
300305
tok->quote_char = c;
@@ -764,6 +769,13 @@ struct json_object* json_tokener_parse_ex(struct json_tokener *tok,
764769
} /* while(POP_CHAR) */
765770

766771
out:
772+
if (c &&
773+
(state == json_tokener_state_finish) &&
774+
(tok->depth == 0) &&
775+
(tok->flags & JSON_TOKENER_STRICT)) {
776+
/* unexpected char after JSON data */
777+
tok->err = json_tokener_error_parse_unexpected;
778+
}
767779
if (!c) { /* We hit an eof char (0) */
768780
if(state != json_tokener_state_finish &&
769781
saved_state != json_tokener_state_finish)

0 commit comments

Comments
 (0)