Repository navigation
Accept zero with an exponent and reject an empty number - #232
Open
emincan2000 wants to merge 1 commit into
Open
emincan2000 wants to merge 1 commit into
emincan2000 wants to merge 1 commit into
Conversation
is_decimal rejected valid numbers like 0e5 because it wanted a dot after a leading zero. It also accepted a lone minus, where strtod converts nothing, and parsed it as 0.
This branch has not been deployed
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.
is_decimal rejects numbers starting with 0 unless a dot follows, so valid JSON like 0e5, 0E+5 and -0e-5 fails to parse. It now rejects a leading zero only when another digit follows.
It also accepts a lone minus. strtod converts nothing, the length is 0, and json_parse_string("-") returns the number 0. The same happens for --1 and -e5. Empty numbers are now rejected.
I added cases to test_suite_3 that fail on master. make test, testcpp and test_hash_collisions all pass with the fix. I also compared old and new builds on about 62k inputs under ASan and UBSan, using Python's json module to distinguish valid from invalid inputs: no valid input became rejected. Trailing characters at the top level are still ignored, so 0e5, parses the same way 1e5, does.