Skip to content

Commit c5cb313

Browse files
res2kbaylesj
authored andcommitted
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.
1 parent abcd3f7 commit c5cb313

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/lib_json/json_reader.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,12 +1051,9 @@ bool OurReader::parse(const char* beginDoc,
10511051
nodes_.pop();
10521052
Token token;
10531053
skipCommentTokens(token);
1054-
if (features_.failIfExtra_) {
1055-
if ((features_.strictRoot_ || token.type_ != tokenError) &&
1056-
token.type_ != tokenEndOfStream) {
1057-
addError("Extra non-whitespace after JSON value.", token);
1058-
return false;
1059-
}
1054+
if (features_.failIfExtra_ && (token.type_ != tokenEndOfStream)) {
1055+
addError("Extra non-whitespace after JSON value.", token);
1056+
return false;
10601057
}
10611058
if (collectComments_ && !commentsBefore_.empty())
10621059
root.setComment(commentsBefore_, commentAfter);

0 commit comments

Comments
 (0)