diff options
author | Eric Haszlakiewicz <erh+git@nimenees.com> | 2013-09-08 13:29:05 -0700 |
---|---|---|
committer | Eric Haszlakiewicz <erh+git@nimenees.com> | 2013-09-08 13:29:05 -0700 |
commit | 02aa6f01f4238a1d5268e514c05ff2fc43e82f5c (patch) | |
tree | dd89063717649341af1f61ac00301864c88102f1 | |
parent | 8356ecc16bbfe727edd7f3bcab39bc5f1c4a3ac8 (diff) | |
parent | 4039f91cab283b483094dbe59202818bb1733d66 (diff) | |
download | json-c-02aa6f01f4238a1d5268e514c05ff2fc43e82f5c.tar.gz |
Merge pull request #94 from remicollet/issue-strict2
more strictness
-rw-r--r-- | json_tokener.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/json_tokener.c b/json_tokener.c index 7b3a097..8019d70 100644 --- a/json_tokener.c +++ b/json_tokener.c @@ -265,7 +265,7 @@ struct json_object* json_tokener_parse_ex(struct json_tokener *tok, if ((!ADVANCE_CHAR(str, tok)) || (!PEEK_CHAR(c, tok))) goto out; } - if(c == '/') { + if(c == '/' && !(tok->flags & JSON_TOKENER_STRICT)) { printbuf_reset(tok->pb); printbuf_memappend_fast(tok->pb, &c, 1); state = json_tokener_state_comment_start; @@ -293,8 +293,13 @@ struct json_object* json_tokener_parse_ex(struct json_tokener *tok, printbuf_reset(tok->pb); tok->st_pos = 0; goto redo_char; - case '"': case '\'': + if (tok->flags & JSON_TOKENER_STRICT) { + /* in STRICT mode only double-quote are allowed */ + tok->err = json_tokener_error_parse_unexpected; + goto out; + } + case '"': state = json_tokener_state_string; printbuf_reset(tok->pb); tok->quote_char = c; @@ -764,6 +769,13 @@ struct json_object* json_tokener_parse_ex(struct json_tokener *tok, } /* while(POP_CHAR) */ out: + if (c && + (state == json_tokener_state_finish) && + (tok->depth == 0) && + (tok->flags & JSON_TOKENER_STRICT)) { + /* unexpected char after JSON data */ + tok->err = json_tokener_error_parse_unexpected; + } if (!c) { /* We hit an eof char (0) */ if(state != json_tokener_state_finish && saved_state != json_tokener_state_finish) |