Skip to content

Fix BigInt JSON parse errors - #3467

Closed
bobzhang wants to merge 1 commit into
mainfrom
codex/fix-bigint-from-json-errors
Closed

Fix BigInt JSON parse errors#3467
bobzhang wants to merge 1 commit into
mainfrom
codex/fix-bigint-from-json-errors

Conversation

@bobzhang

Copy link
Copy Markdown
Contributor

Summary

  • Validate BigInt JSON decimal strings before calling the aborting parser
  • Return JsonDecodeError for malformed string payloads instead of aborting
  • Add bigint package tests for empty, sign-only, and non-digit JSON strings

Tests

  • moon fmt bigint
  • moon info bigint
  • moon test bigint
  • moon test json
  • moon check
  • moon test

@coveralls

Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 3926

Coverage increased (+0.003%) to 94.892%

Details

  • Coverage increased (+0.003%) from the base build.
  • Patch coverage: 9 of 9 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 15584
Covered Lines: 14788
Line Coverage: 94.89%
Coverage Strength: 220180.39 hits per line

💛 - Coveralls

@bobzhang

Copy link
Copy Markdown
Contributor Author

Superseded by #3679 (9d0169eb, merged 2026-07-17), which removed the
// TODO: Capture parse failure this PR targeted and replaced it with:

parse_bigint(s.view()) catch {
  _ => raise JsonDecodeError(
    (path, "BigInt::from_json: invalid number in string representation"))
}

That handles every malformed payload in a single pass, rather than pre-validating
with a separate digit scan and then parsing again.

Verified on current main that the reported failures no longer reproduce — on
native, js and wasm-gc, all of "", "-", "12a", "+5", " 1", "1 ",
"--1", "0", "0x10" return JsonDecodeError, and "-0" returns Ok(0).

The regression tests are already covered too: bigint/parse_bigint_test.mbt
pins "" / "-" / "12a" individually, bigint/quickcheck_deep_test.mbt has a
cross-target rejection table containing them, and json/from_json_test.mbt
covers the adapter turning a parse failure into JsonDecodeError.

Closing — nothing left to land.

@bobzhang bobzhang closed this Aug 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants