Repository navigation
edit: keep a CRLF file's line endings when JSON members are added or replaced - #830
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.
yetone
pushed a commit
that referenced
this pull request
Oct 4, 2026
…AMLStrings rewrite it (#831) * edit: keep a CRLF file's line endings when JSON members are added or 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. * edit: keep a CRLF file's line endings when SetYAML, DelYAML and EditYAMLStrings 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 problem as #829, in JSON. A JSON or JSONC file saved with
\r\n(VS Code on Windows does that) got a bare\non every lineSetJSONadded, becauseinsertKeyandmarshalAtbuild the new lines with\n:The result is now written back through
keepCRLF, which turns every line break into\r\nwhen the original used\r\nfor all of them. Untouched lines already carry their\r, so only the added lines change. A file that already mixed endings is written as before.Tests:
TestSetJSONKeepsCRLFfails on the old code;TestSetJSONKeepsMixedEndingspins that a mixed file is left alone.Run:
go vetandgo test -tags nogui ./internal/edit ./internal/agentpass on this branch and on current main with it merged. Not run: the full./...suite and the GUI tests. This touches onlyjson.go, so it does not conflict with #829.SetJSONIteminjsonarray.gohas the same gap; I left it out because the branch base predates that file, and will send it after this merges. Prepared with AI assistance.