Repository navigation
Fix JsonScanner number parsing for bare exponents and -Infinity - #16284
Conversation
Two bugs found while adding test coverage for JsonReader/JsonWriter on 8.1.x, cherry-picked here since JsonScanner is unchanged since 7.0.x: - SAW_EXPONENT_DIGITS was the only numeric scanner state whose terminator switch omitted an explicit end-of-input case (every sibling state treats EOF the same as a closing delimiter), so a bare exponent-notation number with nothing following it (e.g. a top-level "1e2") threw JsonParseException instead of parsing. - SAW_MINUS_I appended the character it read on every iteration of its "-Infinity" match loop, including the terminator character read immediately after matching the literal's final 'y' - so the buffer handed to Double.parseDouble always carried one extra trailing character, and "-Infinity" failed to parse in every context (end-of-input, before a comma, before a closing bracket). This branch has no prior JsonReader test coverage, so a minimal JsonReaderSpec is added here with just the two regression tests - broader JsonReader/JsonWriter coverage exists only on 8.1.x. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QAjfckcY4EJsxranv1RyGV
There was a problem hiding this comment.
Pull request overview
This pull request fixes two edge-case bugs in the BSON JSON parsing implementation (JsonScanner) and adds targeted regression coverage to prevent reintroduction. It improves correctness for numeric tokenization at end-of-input and for the -Infinity literal, which are both important for robust JSON/BSON interoperability in the grails-data-mongodb module.
Changes:
- Fix
SAW_EXPONENT_DIGITSto correctly terminate on end-of-input (-1) so top-level exponent numbers like1e2parse successfully. - Fix
-Infinityscanning to avoid appending the post-literal terminator character into the numeric buffer (preventingDouble.parseDoublefailures). - Add a minimal
JsonReaderSpecwith two regression tests covering these scenarios.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| grails-data-mongodb/bson/src/main/groovy/org/grails/datastore/bson/json/JsonScanner.java | Correct EOF handling for exponent parsing and fix -Infinity buffer construction so numeric parsing succeeds across delimiters/EOF. |
| grails-data-mongodb/bson/src/test/groovy/org/grails/datastore/bson/json/JsonReaderSpec.groovy | Add regression tests validating bare exponent parsing and -Infinity parsing at EOF and inside an array. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
🚨 TestLens detected 1 failed test 🚨Here is what you can do:
Test SummaryGroovy Snapshot Canary Build / Build Grails (shard 2) > :grails-test-examples-scaffolding:integrationTest
🏷️ Commit: 070707e Test FailuresUserControllerSpec > User list (:grails-test-examples-scaffolding:integrationTest in Groovy Snapshot Canary Build / Build Grails (shard 2))Rerun ControlsSelect tests to mute in this pull request:
Reuse successful test results:
Click the checkbox to trigger a rerun:
Learn more about TestLens at testlens.app/docs. |
Summary
SAW_EXPONENT_DIGITSwas the only numeric scanner state whose terminator switch omitted an explicit end-of-input case, so a bare exponent-notation number with nothing following it (e.g. a top-level1e2) threwJsonParseExceptioninstead of parsing.SAW_MINUS_Iappended the character it read on every iteration of its-Infinitymatch loop, including the terminator character read immediately after matching the literal's finaly- so the buffer handed toDouble.parseDoublealways carried one extra trailing character, and-Infinityfailed to parse in every context (end-of-input, before a comma, before a closing bracket).JsonReader/JsonWritertest coverage on8.1.x;JsonScanneris unchanged since7.0.x, so the fix applies cleanly here. This branch had no priorJsonReadertest coverage, so a minimalJsonReaderSpecis added with just the two regression tests.Test plan
./gradlew :grails-data-mongodb-bson:test- full module suite green, including the two new regression tests./gradlew :grails-data-mongodb-bson:codeStyle- clean🤖 Generated with Claude Code
https://claude.ai/code/session_01QAjfckcY4EJsxranv1RyGV