fix(core): Preserve trailing whitespace in newString during edits - #1688
Merged
Conversation
Remove unconditional trimming of trailing whitespace from newString in normalizeEditStrings(). This fixes cases where intentional trailing whitespace (e.g., in multi-line strings, heredocs) was being stripped. The oldString fuzzy matching still works correctly, and newString is now preserved exactly as the LLM intended. Fixes #1618 Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
tanzhenxin
requested review from
DennisYu07,
LaZzyMan,
Mingholy,
gwinthis and
pomelo-nwu
as code owners
February 2, 2026 03:40
Contributor
📋 Review SummaryThis PR addresses issue #1618 by removing the unconditional stripping of trailing whitespace from 🔍 General Feedback
🎯 Specific Feedback🟡 High
🟢 Medium
🔵 Low
✅ Highlights
|
Contributor
Code Coverage Summary
CLI Package - Full Text ReportCore Package - Full Text ReportFor detailed HTML reports, please see the 'coverage-reports-22.x-ubuntu-latest' artifact from the main CI run. |
xaelistic
pushed a commit
to xaelistic/qwen-code
that referenced
this pull request
Jun 7, 2026
xaelistic
pushed a commit
to xaelistic/qwen-code
that referenced
this pull request
Jun 7, 2026
…espace-1618 fix(core): Preserve trailing whitespace in newString during edits
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.
TLDR
Fixes an issue where trailing whitespace in
newStringwas being unconditionally stripped during file edits, breaking legitimate use cases like multi-line strings with intentional trailing spaces.Dive Deeper
The
normalizeEditStrings()function ineditHelper.tspreviously stripped trailing whitespace fromnewStringas a "cleanup" step. However, this broke valid editing scenarios where trailing whitespace is intentional:This change removes the
stripTrailingWhitespacePreserveNewlines()function and preservesnewStringexactly as provided by the LLM. TheoldStringfuzzy matching continues to work correctly (finding the canonical text from disk), but the replacement text is now preserved verbatim.Key changes:
stripTrailingWhitespacePreserveNewlines()functionnormalizeEditStrings()to passnewStringthrough unchangedReviewer Test Plan
Run the new test suite:
Verify the fix works with a real edit scenario:
Testing Matrix
Note: Tests were run on macOS with
npx vitest run src/utils/editHelper.test.ts- all 34 tests passing.Linked issues / bugs
Fixes #1618
🤖 Generated with Qwen Code