test(jsonparse): cover the JSON number grammar - #23
Merged
Merged
Conversation
Regression tests for the parse_number tightening (RFC 8259). The previous parser grabbed a run of number-ish chars and passed it to std::stod, so it accepted malformed numbers (+1, 01, 1., 1e, .5) and silently mis-parsed multi-token forms (1.2.3 -> 1.2, advancing the cursor past the rest). Adds assertions to test_jsonparse that every well-formed number is accepted with its value preserved, each malformed form is rejected, and a malformed number inside an array/object fails the whole parse rather than truncating the value and continuing from the wrong offset. Unit checks 1339 -> 1376. No production code change.
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.
Summary
Adds regression tests for the JSON number grammar, following up the
parse_numbertightening in #21. Test-only, no production code change.Why
The previous
parse_numbergrabbed a run of number-ish characters and passedit to
std::stod, so it accepted malformed numbers (+1,01,1.,1e,.5) and silently mis-parsed multi-token forms (1.2.3->1.2, advancing thecursor past the rest and continuing the parse from the wrong offset). #21
rewrote the parser to the RFC 8259 grammar; this locks that behavior in.
What
test_jsonparsegains:0,-0,fractions, exponents with signs,
-0.0, etc.);+1,01,-01,00,1.,1e,1e+,.5,1.2.3,1..2,1e5e6,1.e5,--1,-,0x10);truncating the value.
Testing
Unit checks 1339 -> 1376, 0 failures. Full
tests/run.shgreen, and the unitsuite is clean under ASan+UBSan.