From c7321b010729873de9716b831c2c0d361f4acd72 Mon Sep 17 00:00:00 2001 From: Eric Wheeler Date: Thu, 20 Mar 2025 22:08:23 -0700 Subject: [PATCH] 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: #1350 Signed-off-by: Eric Wheeler --- src/core/diff/strategies/multi-search-replace.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/core/diff/strategies/multi-search-replace.ts b/src/core/diff/strategies/multi-search-replace.ts index 852d3dcfbc..238d218e62 100644 --- a/src/core/diff/strategies/multi-search-replace.ts +++ b/src/core/diff/strategies/multi-search-replace.ts @@ -275,6 +275,19 @@ Only use a single line of '=======' between search and replacement content, beca replaceContent = stripLineNumbers(replaceContent) } + // Validate that search and replace content are not identical + if (searchContent === replaceContent) { + diffResults.push({ + success: false, + error: + `Search and replace content are identical - no changes would be made\n\n` + + `Debug Info:\n` + + `- Search and replace must be different to make changes\n` + + `- Use read_file to verify the content you want to change`, + }) + continue + } + // Split content into lines, handling both \n and \r\n const searchLines = searchContent === "" ? [] : searchContent.split(/\r?\n/) const replaceLines = replaceContent === "" ? [] : replaceContent.split(/\r?\n/)