Skip to content

fix: Properly handle keys with whitespace around dot-separated parts - #297

Merged
DecimalTurn merged 11 commits into
latestfrom
dev-space-key
Sep 1, 2026
Merged

fix: Properly handle keys with whitespace around dot-separated parts#297
DecimalTurn merged 11 commits into
latestfrom
dev-space-key

Conversation

@DecimalTurn

@DecimalTurn DecimalTurn commented Sep 1, 2026

Copy link
Copy Markdown
Owner

I disapprove of how you format your TOML files, but I will defend to the death your right format it in that way.
- Anonymous

Whitespace around dot-separated parts is ignored. However, best practice is to not use any extraneous whitespace.
- TOML Spec

Example:

fruit.name = "banana"       # this is best practice
fruit. color = "yellow"     # same as fruit.color
fruit . flavor = "banana"   # same as fruit.flavor

This PR fixes patching issues caused by the use of extranous whitespace in dotted-keys.
Also, since the original fuzzer didn't emit TOML data with this feature, a seperate fuzzer (wrapper) was created to generate that type of TOML data.

Copilot AI lite review requested due to automatic review settings September 1, 2026 21:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The parser’s dotted-key raw reconstruction currently normalizes separator whitespace to spaces (losing tabs), and there’s a duplicated test block that should be removed.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR improves toml-patch’s handling of TOML dotted keys that contain whitespace around dot separators, ensuring patch operations preserve the original key formatting (and adds a second fuzz harness to exercise this syntax).

Changes:

  • Preserve whitespace around dotted-key separators when inserting/renaming keys (including table headers) during patching.
  • Update parsing to retain spacing around dotted key separators in key.raw.
  • Add targeted regression tests plus a new fuzz harness/runner (fuzz2) and a stability test locking the fuzz inputs.
File summaries
File Description
src/patch.ts Adds helpers to detect/reapply dotted-key separator spacing and uses them during inserts/renames.
src/parse-toml.ts Adjusts dotted-key raw reconstruction to include spacing around . separators.
src/tests/patch.indentation.test.ts Updates commentary around potential future multiline formatting options.
src/tests/patch.dotted-key-spacing.test.ts Promotes previously failing dotted-key spacing tests to passing and adds broader coverage for spaced table titles and related ops.
src/tests/fuzz-stability.test.ts Locks fuzz-generated TOML inputs via length + SHA-256 to make fuzz inputs stable over time.
src/tests/fuzz-patch2.ts Introduces a fuzz harness variant that spaces dotted-key separators before patching.
src/tests/fuzz-patch.ts Extends fuzz runner to support source transforms and optional indent-width randomization.
scripts/fuzz-run2.ts Adds a CLI runner for the second fuzz harness.
package.json Adds npm run fuzz2 script for the new fuzz runner.
docs/Formatting.md Clarifies legacy anonymous formatting object usage vs recommended type-safe approach.
Review details
  • Files reviewed: 11/11 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/parse-toml.ts Outdated
Comment thread docs/Formatting.md
Comment thread src/__tests__/patch.dotted-key-spacing.test.ts Outdated
@DecimalTurn
DecimalTurn marked this pull request as ready for review September 1, 2026 22:05
@DecimalTurn
DecimalTurn merged commit 8930d99 into latest Sep 1, 2026
31 checks passed
@DecimalTurn
DecimalTurn deleted the dev-space-key branch September 1, 2026 22:05
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