Skip to content

fix: normalize CRLF line endings in edit tool parameters#2474

Closed
Br1an67 wants to merge 1 commit intoQwenLM:mainfrom
Br1an67:fix/table-pipe-escape
Closed

fix: normalize CRLF line endings in edit tool parameters#2474
Br1an67 wants to merge 1 commit intoQwenLM:mainfrom
Br1an67:fix/table-pipe-escape

Conversation

@Br1an67
Copy link
Copy Markdown
Contributor

@Br1an67 Br1an67 commented Mar 19, 2026

TLDR

Fixes the Edit tool failing on multi-line edits when old_string contains CRLF (\r\n) line endings but the file content has been normalized to LF (\n). This is a one-line root cause fix plus a regression test.

Dive Deeper

The Edit tool already normalizes file content from CRLF to LF on read (edit.ts:163):

currentContent = fileInfo.content.replace(/\r\n/g, '\n\);

However, the old_string and new_string parameters were not normalized, so when an LLM or Windows IDE provides old_string with CRLF line endings, indexOf() fails to find a match against the LF-normalized content. This is especially common with UTF-8 BOM + CRLF projects on Windows (as reported in #2257).

The fix adds matching CRLF→LF normalization for old_string and new_string before the matching logic runs:

finalOldString = finalOldString.replace(/\r\n/g, '\n\);
finalNewString = finalNewString.replace(/\r\n/g, '\n\);

Reviewer Test Plan

  1. Create a file with CRLF line endings on Windows (or printf "line1\r\nline2\r\nline3" > test.txt)
  2. Use the Edit tool with a multi-line old_string containing CRLF
  3. Verify the edit succeeds (previously would fail with "no match found")

Testing Matrix

🍏 🪟 🐧
npm run
npx

Linked issues / bugs

Fixes #2257

…arameters

When old_string is provided with CRLF line endings (e.g. from a Windows
IDE or LLM output), it fails to match the LF-normalized file content,
causing multi-line edits to fail silently.

The file content is already normalized from CRLF to LF on read (line 163),
but the old_string and new_string parameters were not. This adds matching
normalization for both parameters before the matching logic runs.

Fixes QwenLM#2257

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@tanzhenxin
Copy link
Copy Markdown
Collaborator

This issue cannot be reproduced on Windows system, with utf-8 bom + CRLF newlines. I suspect the real edit problem is related to #1922 , which involved mixed Chinese/English character.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vscode中的QwenCode编辑代码时报错:Edit 工具用 LF 匹配,文件是 CRLF,多行匹配失败

2 participants