fix: Properly handle keys with whitespace around dot-separated parts - #297
Merged
Conversation
There was a problem hiding this comment.
🟡 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.
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.
Example:
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.