Skip to content

jlexer: enforce RFC 8259 number grammar (no leading zeros)#442

Open
omkhar wants to merge 1 commit into
mailru:masterfrom
omkhar:omkhar/enforce-number-grammar
Open

jlexer: enforce RFC 8259 number grammar (no leading zeros)#442
omkhar wants to merge 1 commit into
mailru:masterfrom
omkhar:omkhar/enforce-number-grammar

Conversation

@omkhar

@omkhar omkhar commented Jun 27, 2026

Copy link
Copy Markdown

Problem

fetchNumber accepts number literals that violate the RFC 8259 number grammar — leading zeros ({"i":01}1, 0077, 0123123 as decimal, -007-7) and a trailing dot ({"f":1.}1). encoding/json rejects all of these ("invalid character … after …").

Same parser-differential / JSON-interoperability class as #375: a strict validator rejects the document as malformed while easyjson silently accepts it and assigns a non-obvious value.

Reproduce (current master): {"i":01} decodes with a nil error into I=1; encoding/json rejects it.

Fix

Enforce the RFC 8259 number grammar in fetchNumber: reject a leading zero in the integer part followed by another digit, and require at least one digit after . and after e/E.

  • jlexer/lexer.go: +44/-3, contained to fetchNumber.
  • go test ./... passes (jlexer, gen, parser, buffer, tests).

Same rollout question as the control-char change: this tightens default parsing. If you'd prefer it opt-in (cf. -disallow_duplicate_fields, #375; -disallow_unknown_fields), happy to rework. Flagging the trade-off rather than assuming.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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