mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 12:21:13 -05:00
Instead of trusting the prompt, just strip line numbers from diff contents
This commit is contained in:
@@ -131,10 +131,25 @@ Your search/replace content here
|
||||
};
|
||||
}
|
||||
|
||||
const [_, searchContent, replaceContent] = match;
|
||||
let [_, searchContent, replaceContent] = match;
|
||||
|
||||
// Detect line ending from original content
|
||||
const lineEnding = originalContent.includes('\r\n') ? '\r\n' : '\n';
|
||||
|
||||
// Strip line numbers from search and replace content if every line starts with a line number
|
||||
const hasLineNumbers = (content: string) => {
|
||||
const lines = content.split(/\r?\n/);
|
||||
return lines.length > 0 && lines.every(line => /^\d+\s+\|(?!\|)/.test(line));
|
||||
};
|
||||
|
||||
if (hasLineNumbers(searchContent) && hasLineNumbers(replaceContent)) {
|
||||
const stripLineNumbers = (content: string) => {
|
||||
return content.replace(/^\d+\s+\|(?!\|)/gm, '')
|
||||
};
|
||||
|
||||
searchContent = stripLineNumbers(searchContent);
|
||||
replaceContent = stripLineNumbers(replaceContent);
|
||||
}
|
||||
|
||||
// Split content into lines, handling both \n and \r\n
|
||||
const searchLines = searchContent.split(/\r?\n/);
|
||||
|
||||
Reference in New Issue
Block a user