Repository navigation
Accept a comment directly after a number - #136
Merged
Merged
Conversation
With json_parse_flags_allow_c_style_comments, a comment is accepted after a string, literal or a space, but json_get_number_size only ended a number at whitespace, '}', ',', ']' or '=', so [1/* a */,2] failed with invalid_number_format. Let '/' end a number when comments are on.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
json_parse_flags_allow_c_style_comments(and soallow_json5), a comment is accepted after a string, a literal or a space, but not directly after a number:[1/*x*/,2][1,2]{a:1// x\n}[1 /*x*/,2],["a"/*x*/,2],[true/*x*/]The number terminator switch in
json_get_number_sizehas a case for=underallow_equals_in_objectbut none for/. This adds the same case for/underallow_c_style_comments; without the flag it is stillinvalid_number_format. npmjson5parses the test payload[-1.5e3/* a */,2// b\n]to[-1500,2].after_numberandafter_number_without_flagfollow the otherallow_c_style_commentstests intest/test_shared.h; the first fails on main. The suite passes in gcc Debug and Release builds and in a Debug build with ASan and UBSan, and inputs ending right after the/(1/,[1/,[1/*) read past nothing. I did not run clang, tcc or MSVC.An unterminated
/*at the end of the input is accepted (1 /*on main too), so1/*now parses;json_skip_c_style_commentsreturns 1 for it although its comment calls it a failure. I can send that separately.Written with AI assistance (Claude); I have reviewed the change.