fix(toml): emit TOML literals for Infinity/NaN/Date in arrays#7163
Draft
spokodev wants to merge 1 commit into
Draft
fix(toml): emit TOML literals for Infinity/NaN/Date in arrays#7163spokodev wants to merge 1 commit into
spokodev wants to merge 1 commit into
Conversation
Primitive and mixed array stringification went through code paths
that produced invalid TOML for non-finite numbers and Date values:
- `[Infinity, -Infinity, NaN]` rendered as `[null,null,null]`
because `#arrayDeclaration` used `JSON.stringify` which has no
TOML equivalents for those values.
- `[new Date(0)]` rendered as `["1970-01-01T00:00:00.000Z"]` for
the same reason - a quoted ISO string instead of a TOML datetime
literal.
- Mixed arrays like `[Infinity, {}]` and `[new Date(0), {}]` ran
through `#printAsInlineValue` which returned numbers verbatim
(so Infinity printed as the JS identifier) and wrapped Dates in
string quotes.
Introduce `#printPrimitive` that produces TOML-compliant literals
for Date, string, RegExp, number (including inf/-inf/nan) and
boolean. `#arrayDeclaration` and `#printAsInlineValue` now route
primitives through it.
The behaviour for `null`/`undefined` inside arrays is left
unchanged (still throws "Should never reach") since the issue
author flagged it as a design call for the maintainers.
Updates one existing test that encoded the old quoted-Date output
inside a mixed array. The new output matches the TOML 1.0 spec for
datetime literals.
Fixes denoland#7162 (partial - null handling deferred per the issue).
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7163 +/- ##
=======================================
Coverage 94.57% 94.57%
=======================================
Files 636 636
Lines 52142 52147 +5
Branches 9401 9406 +5
=======================================
+ Hits 49315 49320 +5
Misses 2249 2249
Partials 578 578 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Primitive and mixed array stringification went through code paths that produced invalid TOML for non-finite numbers and Date values. The issue author flagged six distinct cases in #7162; this PR addresses the four with a deterministic spec-aligned fix and leaves the two
null-related ones for maintainer guidance, since they are a design call.What changed
#arrayDeclaration(primitive arrays) previously routed values throughJSON.stringify, which has no representation for Infinity, -Infinity, NaN, or TOML datetime literals.#printAsInlineValue(mixed arrays) returned numbers verbatim (so Infinity printed as the JS identifier) and wrapped Dates in string quotes.A new private helper
#printPrimitiveproduces TOML-compliant literals forDate,string,RegExp,number(includinginf/-inf/nan) andboolean. Both array paths now route primitives through it.Behaviour for
null/undefinedinside arrays is unchanged - the code still throwsShould never reach. The issue author flagged this as a design call (TOML has nonull), so it stays as-is until maintainers decide between a clearer error message, silent skip, or another shape.Before/after
Tests
Six new cases in
toml/stringify_test.ts:inf/-inf/nan#printPrimitivepath that replacedJSON.stringify)One existing test (
stringify() handles mixed array) had a date inside a mixed inline-table that was previously emitted with quotes. The expected output is updated to the spec-aligned bare datetime literal.`deno test --allow-all toml/` -> 689 passed, 0 failed, 111 ignored.
`deno fmt` and `deno lint` clean on the changed files.
Fixes #7162 (partial - null handling left for maintainer guidance).