From c5cb313ca0652f5669624648d972d5fbaa96000c Mon Sep 17 00:00:00 2001 From: Frank Richter Date: Mon, 16 Sep 2019 19:41:50 +0200 Subject: [PATCH] Do not allow tokenError tokens after input if failIfExtra is set. (#1014) Currently when failIfExtra is set and strictRoot is not set, OurReader::parse() will accept trailing non-whitespace after the JSON value as long as the first token is not a valid JSON token. This commit changes this to disallow any non-whitespace after the JSON value. This commit also suppresses the "Extra non-whitespace after JSON value." error message if parsing was aborted after another error. --- src/lib_json/json_reader.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp index 8cc4f43..8dad1d1 100644 --- a/src/lib_json/json_reader.cpp +++ b/src/lib_json/json_reader.cpp @@ -1051,12 +1051,9 @@ bool OurReader::parse(const char* beginDoc, nodes_.pop(); Token token; skipCommentTokens(token); - if (features_.failIfExtra_) { - if ((features_.strictRoot_ || token.type_ != tokenError) && - token.type_ != tokenEndOfStream) { - addError("Extra non-whitespace after JSON value.", token); - return false; - } + if (features_.failIfExtra_ && (token.type_ != tokenEndOfStream)) { + addError("Extra non-whitespace after JSON value.", token); + return false; } if (collectComments_ && !commentsBefore_.empty()) root.setComment(commentsBefore_, commentAfter);