Fix JSON reader rejecting exponent notation without a fraction - #560
Open
VXNCXNX wants to merge 1 commit into
Open
Fix JSON reader rejecting exponent notation without a fraction#560VXNCXNX wants to merge 1 commit into
VXNCXNX wants to merge 1 commit into
Conversation
A number was only treated as a float when the literal contained a '.', so 1e3 and 1E-2 were handed to ParseInt and failed. Both are valid JSON, and the YAML reader already classifies them as floats.
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.
What's broken
Valid JSON numbers in exponent notation without a decimal point are rejected outright.
Repro
2e+2fails the same way.The fix
decodeTokenonly treated a number as a float when the literal contained a., so the exponent forms went toParseInt. It now also checks foreorE. Those are the only other charactersjson.Numbercan hold, so there is no false positive.Verification
TestJSONReader_ExponentNumberscovers positive, negative and signed exponents, a fraction with an exponent, and plain integers staying ints. Reverting to the.check fails it on the parse error.I compared binaries built before and after across the number forms rather than reasoning from the diff:
1,-3,0,1.0,1.5and an 18 digit integer all produce byte-identical output. Only the three exponent forms change, from an error to a value.One consequence worth naming:
1e3now reads as a float, so-o yamlgives!!float 1000. The YAML reader already did exactly that for1e3on master, so this aligns the two readers rather than introducing a new behaviour.go test ./...passes across all 21 packages.gofmtandgo vetclean. CHANGELOG entry added under Unreleased/Fixed.