Fix JsonDecoder parsing of large floats with e+ scientific notation#49
Merged
Fix JsonDecoder parsing of large floats with e+ scientific notation#49
Conversation
Co-authored-by: streamich <9773803+streamich@users.noreply.github.com>
…float tests Co-authored-by: streamich <9773803+streamich@users.noreply.github.com>
Copilot
AI
changed the title
[WIP]
Fix JsonDecoder parsing of large floats with e+ scientific notation
Aug 8, 2025
JsonDecoder hardening
streamich
requested changes
Aug 8, 2025
| * Large floating point numbers and edge cases that should be handled correctly | ||
| * by JSON decoders, especially those with scientific notation (e+/e-). | ||
| */ | ||
| export default { |
Collaborator
There was a problem hiding this comment.
Use these fixtures in JsonDecoder tests.
|
🎉 This PR is included in version 1.10.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
The
JsonDecoder.readNum()method had inconsistent character validation logic that prevented parsing of large floating point numbers with explicit plus signs in scientific notation (e.g.,1.7976931348623157e+308).Problem
The issue occurred because the method's unrolled character-by-character parsing loop had different validation conditions at different positions:
+signs with conditionc !== 43(where 43 is the ASCII code for+)c !== 43check, causing numbers with+signs appearing after position 8 to fail parsingThis meant that
1.7976931348623157e+308(where+appears at position 19) would throw "Invalid JSON" error, while1.7976931348623157e308(without explicit+) worked correctly.Solution
Added the missing
c !== 43checks to all character validation conditions from position 9 onwards in thereadNum()method. This ensures consistent handling of plus signs throughout the entire number parsing process.Testing
Number.MAX_VALUE2e+308) and very small numbers (5e-324)The fix now correctly handles all standard JSON number formats including large floats that reach JavaScript's numeric limits.
Fixes #48.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.