Skip to content

Commit c7321b0

Browse files
author
Eric Wheeler
committed
fix: reject apply_diff when search matches replace content
Prevents attempting to apply diffs where search and replace content are identical, which would result in no changes being made. Instead, provide a helpful error message explaining why the operation was rejected. Fixes: RooCodeInc#1350 Signed-off-by: Eric Wheeler <roo-code@z.ewheeler.org>
1 parent 1b8bac6 commit c7321b0

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/core/diff/strategies/multi-search-replace.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,19 @@ Only use a single line of '=======' between search and replacement content, beca
275275
replaceContent = stripLineNumbers(replaceContent)
276276
}
277277

278+
// Validate that search and replace content are not identical
279+
if (searchContent === replaceContent) {
280+
diffResults.push({
281+
success: false,
282+
error:
283+
`Search and replace content are identical - no changes would be made\n\n` +
284+
`Debug Info:\n` +
285+
`- Search and replace must be different to make changes\n` +
286+
`- Use read_file to verify the content you want to change`,
287+
})
288+
continue
289+
}
290+
278291
// Split content into lines, handling both \n and \r\n
279292
const searchLines = searchContent === "" ? [] : searchContent.split(/\r?\n/)
280293
const replaceLines = replaceContent === "" ? [] : replaceContent.split(/\r?\n/)

0 commit comments

Comments
 (0)