Skip to content

fix: reject leading zeros in numbers per RFC 8259 - #1145

Open
ScheizerDiem wants to merge 1 commit into
DaveGamble:masterfrom
ScheizerDiem:fix-leading-zeros
Open

ScheizerDiem wants to merge 1 commit into
DaveGamble:masterfrom
ScheizerDiem:fix-leading-zeros

Conversation

@ScheizerDiem

Copy link
Copy Markdown

Fixes #718.

According to RFC 8259 (Section 6), JSON numbers cannot contain leading zeros unless the integer part is a single 0 (e.g. 0, -0, 0.5, 0e10). Previously, parse_number passed the input directly to strtod, which accepted invalid inputs such as [000000], 01, and -01.

Changes

  • Reject numbers starting with 0 or -0 immediately followed by another ASCII digit (0–9) in parse_number before allocating the temporary buffer.
  • Added unit tests in tests/parse_number.c covering invalid leading-zero cases (00, 000000, 01, -00, -01, 01.5, -01e2).

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.

Accepting invalid integers

1 participant