Repository navigation
edit: keep a CRLF file's line endings when SetYAML, DelYAML and EditYAMLStrings rewrite it - #831
Merged
Merged
Conversation
…replaced
SetJSON splices new lines into the file with \n. In a JSON or JSONC file saved with \r\n (VS Code on Windows does that), a member added to an object or a nested value came back with a bare \n among the \r\n lines. SetJSON of "b" on "{\r\n \"a\": 1\r\n}\r\n" gave "{\n \"b\": 2,\r\n \"a\": 1\r\n}\r\n".
The result is written back through keepCRLF, which turns every line break into \r\n when the original used \r\n for all of them. Untouched lines already carry their \r, so only the added lines change; a file that mixed endings is written as before.
TestSetJSONKeepsCRLF fails on the old code; TestSetJSONKeepsMixedEndings pins that a mixed file is left alone. go vet and go test ./internal/edit pass here and on current main with this merged.
…AMLStrings rewrite it writeYAML renders the whole document with the YAML encoder, which writes \n. A YAML file saved with \r\n (the usual case for one edited on Windows) came back entirely LF after any SetYAML, DelYAML or EditYAMLStrings, so an edit of one key rewrote every line of the file and showed up as a full-file diff. The result is written back through keepCRLF, which turns every line break into \r\n when the original used \r\n for all of them. A LF or mixed file is written as before. TestSetYAMLKeepsCRLF fails on the old code; TestSetYAMLKeepsLF pins that an LF file is unchanged. This builds on the keepCRLF added for SetJSON in the previous commit (#830). go vet and go test ./internal/edit ./internal/agent ./internal/library ./internal/settings pass.
yetone
added a commit
that referenced
this pull request
Oct 4, 2026
… with no trailing break, in a multi-line TOML string, a YAML block scalar and after DelJSON (review of #829, #830, #831) — tests only. TestReviewLFUntouched and TestReviewCRLFEdges; the CRLF cases fail on the code before those PRs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner
|
Thanks @charan-rathore, merged and released in v0.1.915. I pulled #829, #830 and #831 together onto main and checked them:
I also added review tests (
All of them pass. |
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.
Same family as #829 and #830, for the YAML round trip.
writeYAMLrenders the whole document with the YAML encoder, which writes\n. A YAML file saved with\r\ncame back entirely LF after anySetYAML,DelYAMLorEditYAMLStrings, so changing one key rewrote every line.The result is now written back through
keepCRLF, which turns every line break into\r\nwhen the original used\r\nfor all of them. An LF or mixed file is written as before.This branch is stacked on #830 (it uses the
keepCRLFthat PR adds), so the diff shows that commit until #830 merges; the YAML change is the last commit,internal/edit/yaml.goandcrlf_yaml_test.go.Tests:
TestSetYAMLKeepsCRLFfails on the old code;TestSetYAMLKeepsLFpins that an LF file is unchanged.Run:
go vetandgo test -tags nogui ./internal/edit ./internal/agent ./internal/library ./internal/settingspass here, and./internal/editpasses on current main with this merged. Not run: the full./...suite and the GUI tests. Prepared with AI assistance.