Skip to content

Canonicalize integers as doubles in RFC 8785 mode - #1103

Merged
byroot merged 1 commit into
ruby:masterfrom
ydah:fix-rfc8785-integer-formatting
Oct 8, 2026
Merged

byroot merged 1 commit into
ruby:masterfrom
ydah:fix-rfc8785-integer-formatting

Conversation

@ydah

@ydah ydah commented Oct 8, 2026

Copy link
Copy Markdown
Member

RFC 8785 §3.2.2.3 requires ECMAScript serialization of double-precision numbers. Integer generation currently bypasses the canonical number formatter.

JSON.generate(9007199254740993, rfc8785: true)
# Before: "9007199254740993"
# After:  "9007199254740992"

JSON.generate(10**21, rfc8785: true)
# Before: "1000000000000000000000"
# After:  "1e+21"

Route integers through the existing formatter after converting to Float. Reject integers outside the finite Float range with GeneratorError before conversion, avoiding overflow warnings. Ordinary integer generation remains unchanged.

@byroot
byroot merged commit 3d9d6dd into ruby:master Oct 8, 2026
42 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.

2 participants