Skip to content

test(jsonparse): cover the JSON number grammar - #23

Merged
nmatt0 merged 1 commit into
masterfrom
test/jsonparse-number-grammar
Sep 15, 2026
Merged

nmatt0 merged 1 commit into
masterfrom
test/jsonparse-number-grammar

Conversation

@nmatt0

@nmatt0 nmatt0 commented Sep 15, 2026

Copy link
Copy Markdown
Owner

Summary

Adds regression tests for the JSON number grammar, following up the
parse_number tightening in #21. Test-only, no production code change.

Why

The previous parse_number grabbed a run of number-ish characters 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 and continuing the parse from the wrong offset). #21
rewrote the parser to the RFC 8259 grammar; this locks that behavior in.

What

test_jsonparse gains:

  • every well-formed number is accepted with its value preserved (0, -0,
    fractions, exponents with signs, -0.0, etc.);
  • each malformed form is rejected (+1, 01, -01, 00, 1., 1e, 1e+,
    .5, 1.2.3, 1..2, 1e5e6, 1.e5, --1, -, 0x10);
  • a malformed number inside an array/object fails the whole parse rather than
    truncating the value.

Testing

Unit checks 1339 -> 1376, 0 failures. Full tests/run.sh green, and the unit
suite is clean under ASan+UBSan.

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.
@nmatt0
nmatt0 merged commit 59accc8 into master Sep 15, 2026
4 checks passed
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.

1 participant