Skip to content

fix(toml): stringify special values in inline arrays correctly - #7272

Open
YoinkingFishy wants to merge 1 commit into
denoland:mainfrom
YoinkingFishy:fix/toml-inline-array-special-values
Open

fix(toml): stringify special values in inline arrays correctly#7272
YoinkingFishy wants to merge 1 commit into
denoland:mainfrom
YoinkingFishy:fix/toml-inline-array-special-values

Conversation

@YoinkingFishy

Copy link
Copy Markdown

Fixes #7162.

stringify serialized primitive arrays with JSON.stringify, which has several problems for TOML output:

  • Infinity/-Infinity/NaN were turned into null (invalid TOML that fails to parse back)
  • Date values were emitted as quoted ISO strings, so they parsed back as strings instead of Dates
  • RegExp values became {}

Now all inline arrays are emitted element-by-element through #printAsInlineValue, matching how the same values are serialized at the top level:

stringify({ x: [Infinity, -Infinity, NaN] }) // x = [inf,-inf,nan]
stringify({ x: [new Date(0)] })              // x = [1970-01-01T00:00:00.000]
stringify({ x: [Infinity, -Infinity, NaN, {}] }) // x = [inf,-inf,nan,{}]

Arrays containing null/undefined (which TOML cannot represent) now throw Error("Cannot stringify null or undefined values") instead of an opaque Object.keys TypeError or Error("Should never reach").

Testing: deno test --allow-read --allow-run toml/ — 684 passed, 0 failed (111 ignored); deno fmt --check and deno lint clean on changed files.

AI disclosure: this PR was prepared with the assistance of AI tooling; the change was reviewed and verified locally as described above.

Primitive arrays were serialized with JSON.stringify, which turned Infinity, -Infinity and NaN into null, quoted dates, and turned RegExp values into empty objects. Route all inline arrays through the per-element printer instead, matching the scalar handling already used for top-level values.

Inline dates are now emitted unquoted (e.g. 1970-01-01T00:00:00.000) so they parse back into a Date instead of a string.

Arrays containing null or undefined now throw a descriptive error instead of the confusing Object.keys TypeError or the generic 'Should never reach'.
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions github-actions Bot added the toml label Aug 1, 2026
@codecov

codecov Bot commented Aug 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.02%. Comparing base (2d8f5a5) to head (3d7d2c0).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7272      +/-   ##
==========================================
- Coverage   95.02%   95.02%   -0.01%     
==========================================
  Files         618      618              
  Lines       51496    51505       +9     
  Branches     9300     9311      +11     
==========================================
+ Hits        48936    48944       +8     
- Misses       2021     2022       +1     
  Partials      539      539              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@std/toml: Inline array stringification mishandles edge cases

3 participants