Repository navigation
edit: keep a CRLF file's line endings when dotenv, TOML and top-level YAML lines are added or replaced - #829
Merged
Conversation
… YAML lines are added or replaced SetEnvFile, the TOML setters and the top-level YAML setters build the lines they add with \n, then join the whole file. In a file saved with \r\n (the usual case for a config edited on Windows) that left the new or replaced lines with a bare \n among \r\n ones. SetEnvFile turned "A=1\r\nB=2\r\n" with A set to 9 into "A=9\nB=2\r\n", and SetTOMLTop, a new TOML key or table, and SetYAMLTop did the same. The files are written back through joinLinesLike, 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 lines the edit added change; a file that mixed endings is written as before. TestSetEnvFileKeepsCRLF, TestSetTOMLKeepsCRLF and TestSetYAMLTopKeepsCRLF fail on the old code; TestSetEnvFileKeepsMixedEndings pins that a mixed file is left alone. go vet and go test ./internal/edit pass on this branch and on current main with it merged; the full go test -tags nogui ./... run (under a temp HOME) passes except internal/sessions TestCodexArchivedSameSizeRewriteInvalidatesDiscovery, which fails the same way on unmodified main here.
This was referenced Oct 4, 2026
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.
Config files edited on Windows are usually saved with
\r\n.SetEnvFile, the TOML setters (SetTOMLTop,SetTOMLKey,SetTOMLTable) and the top-level YAML setters build the lines they add with\nand join the file, so a CRLF file came back with a bare\non every line the edit added or replaced:The file is now written back through
joinLinesLike, 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:
TestSetEnvFileKeepsCRLF,TestSetTOMLKeepsCRLFandTestSetYAMLTopKeepsCRLFfail on the old code.TestSetEnvFileKeepsMixedEndingspins that a mixed file is left alone.Run:
go vetandgo test -tags nogui ./internal/editpass on this branch, and on current main with it merged;GOOS=windows go buildpasses. The fullgo test -tags nogui -count=1 ./...(temp HOME) passes exceptinternal/sessionsTestCodexArchivedSameSizeRewriteInvalidatesDiscovery, which fails the same way on unmodified main in this environment. Not run: the GUI/WebKit tests. Prepared with AI assistance.JSON edits have the same problem; I will send that separately.