-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix: preserve trailing newlines in stripLineNumbers for apply_diff #8227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Modified stripLineNumbers function to preserve trailing newlines - This fixes issue #8020 where line numbers at the last line were not being stripped correctly - Added comprehensive test cases for trailing newline preservation - All existing tests pass without regression
✅ Review Complete - No Issues FoundI've completed a thorough review of this pull request and found no issues. The implementation correctly fixes the trailing newline preservation bug in Summary✅ Code Quality: Implementation is clean and follows existing patterns The PR is ready for approval by a human reviewer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues found.
Summary
This PR fixes Issue #8020 where
apply_difffails to strip line numbers from the last line in SEARCH and REPLACE blocks, particularly in Windows environments with CRLF line endings.Root Cause
The bug occurs due to an interaction between the regex parser and line number stripping:
multi-search-replace.tsuses(?:\n)?which optionally consumes trailing newlines from captured content\r\n), this can leave content ending with just\r(consuming the\n)stripLineNumbers()processes this malformed content, it splits by/\r?\n/but the line structure is broken1488 |) cannot be matched and stripped properlyExample of the bug:
Solution
Modified
stripLineNumbers()insrc/integrations/misc/extract-text.tsto preserve trailing newlines when present in the original content:This ensures that:
Why Not Fix the Regex Directly?
@daniel-lxs suggested modifying the regex pattern to use lookahead assertions to avoid consuming trailing newlines. However, this approach broke existing deletion tests where the replace block is empty. The current solution is more robust and doesn't require making the already complex regex even more fragile.
Changes
stripLineNumbers()to preserve trailing newlines when present in the original contentTesting
Fixes #8020