mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-21 12:51:17 -05:00
Handle Windows line endings (#62)
This commit is contained in:
@@ -181,6 +181,23 @@ function test() {
|
||||
expect(result).toBe("\tfunction test() {\n\t\t// First comment\n\t\t// Second comment\n\t\treturn true;\n\t}")
|
||||
})
|
||||
|
||||
it('should handle Windows-style CRLF line endings', () => {
|
||||
const originalContent = "function test() {\r\n return true;\r\n}\r\n"
|
||||
const diffContent = `test.ts
|
||||
<<<<<<< SEARCH
|
||||
function test() {
|
||||
return true;
|
||||
}
|
||||
=======
|
||||
function test() {
|
||||
return false;
|
||||
}
|
||||
>>>>>>> REPLACE`
|
||||
|
||||
const result = strategy.applyDiff(originalContent, diffContent)
|
||||
expect(result).toBe("function test() {\r\n return false;\r\n}\r\n")
|
||||
})
|
||||
|
||||
it('should return false if search content does not match', () => {
|
||||
const originalContent = `function hello() {
|
||||
console.log("hello")
|
||||
|
||||
@@ -70,10 +70,13 @@ Your search/replace content here
|
||||
|
||||
const [_, searchContent, replaceContent] = match;
|
||||
|
||||
// Split content into lines
|
||||
const searchLines = searchContent.trim().split('\n');
|
||||
const replaceLines = replaceContent.trim().split('\n');
|
||||
const originalLines = originalContent.split('\n');
|
||||
// Detect line ending from original content
|
||||
const lineEnding = originalContent.includes('\r\n') ? '\r\n' : '\n';
|
||||
|
||||
// Split content into lines, handling both \n and \r\n
|
||||
const searchLines = searchContent.trim().split(/\r?\n/);
|
||||
const replaceLines = replaceContent.trim().split(/\r?\n/);
|
||||
const originalLines = originalContent.split(/\r?\n/);
|
||||
|
||||
// Find the search content in the original
|
||||
let matchIndex = -1;
|
||||
@@ -166,6 +169,6 @@ Your search/replace content here
|
||||
const beforeMatch = originalLines.slice(0, matchIndex);
|
||||
const afterMatch = originalLines.slice(matchIndex + searchLines.length);
|
||||
|
||||
return [...beforeMatch, ...indentedReplace, ...afterMatch].join('\n');
|
||||
return [...beforeMatch, ...indentedReplace, ...afterMatch].join(lineEnding);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user