fix(core): preserve CRLF line endings when editing files#2277
Open
howardpen9 wants to merge 1 commit intoQwenLM:mainfrom
Open
fix(core): preserve CRLF line endings when editing files#2277howardpen9 wants to merge 1 commit intoQwenLM:mainfrom
howardpen9 wants to merge 1 commit intoQwenLM:mainfrom
Conversation
The edit tool normalizes file content from CRLF to LF for matching, but did not restore CRLF when writing back. This silently converted Windows-style line endings to Unix-style, causing massive git diffs and breaking .editorconfig enforcement. Changes: - Detect CRLF before normalization and restore on write-back - Use normalizeContent() utility instead of inline replace (also handles standalone CR and BOM stripping) - Add usesCRLF flag to CalculatedEdit interface - Add 3 tests: CRLF preservation, LF-only file unchanged, BOM preservation Fixes QwenLM#2257
Author
|
123 |
This was referenced Mar 12, 2026
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.
Summary
The edit tool normalizes file content from CRLF to LF for consistent matching, but did not restore CRLF line endings when writing back. This silently converts Windows-style (
\r\n) line endings to Unix-style (\n), causing:.editorconfigenforcement breakageRoot Cause
In
edit.ts,calculateEdit()normalizes content for matching:But the write path passes
editData.newContent(LF-only) directly towriteTextFile()without restoring the original line endings.Changes
packages/core/src/tools/edit.ts:usesCRLF = fileInfo.content.includes('\r\n')normalizeContent()utility (handles CRLF, standalone CR, and BOM) instead of inline replaceusesCRLFflag toCalculatedEditinterfacepackages/core/src/tools/edit.test.ts:should preserve CRLF line endings when editing a CRLF fileshould not inject CRLF when editing a LF fileshould preserve UTF-8 BOM when editing a BOM fileReproduction
git diff— every line shows as changed (line ending conversion)Related
normalizeContent()from fix(cli): parse markdown command frontmatter on Windows CRLF/BOM #2078