diff --git a/aider/coders/editblock_coder.py b/aider/coders/editblock_coder.py index bb0a01914..d8f85da52 100644 --- a/aider/coders/editblock_coder.py +++ b/aider/coders/editblock_coder.py @@ -414,11 +414,15 @@ def strip_filename(filename, fence): start_fence = fence[0] if filename.startswith(start_fence): candidate = filename[len(start_fence) :] - if candidate and "." in candidate: + if candidate and ("." in candidate or "/" in candidate): return candidate + return if filename.startswith(triple_backticks): - filename = filename[len(triple_backticks) :] + candidate = filename[len(triple_backticks) :] + if candidate and ("." in candidate or "/" in candidate): + return candidate + return filename = filename.rstrip(":") filename = filename.lstrip("#") diff --git a/tests/basic/test_editblock.py b/tests/basic/test_editblock.py index d80952bbe..e93edb7c3 100644 --- a/tests/basic/test_editblock.py +++ b/tests/basic/test_editblock.py @@ -108,29 +108,6 @@ Hope you like it! edits = list(eb.find_original_update_blocks(edit)) self.assertEqual(edits, [("foo.txt", "Two\n", "Tooooo\n")]) - def test_find_original_update_blocks_mangled_filename_w_source_tag(self): - source = "source" - - edit = """ -Here's the change: - -<%s>foo.txt -<<<<<<< SEARCH -One -======= -Two ->>>>>>> REPLACE - - -Hope you like it! -""" % (source, source) - - fence = ("<%s>" % source, "" % source) - - with self.assertRaises(ValueError) as cm: - _edits = list(eb.find_original_update_blocks(edit, fence)) - self.assertIn("missing filename", str(cm.exception)) - def test_find_original_update_blocks_quote_below_filename(self): edit = """ Here's the change: @@ -181,10 +158,11 @@ Tooooo oops! +>>>>>>> REPLACE """ with self.assertRaises(ValueError) as cm: - list(eb.find_original_update_blocks(edit)) + _blocks = list(eb.find_original_update_blocks(edit)) self.assertIn("filename", str(cm.exception)) def test_find_original_update_blocks_no_final_newline(self): @@ -575,7 +553,7 @@ Hope you like it! edits = list(eb.find_original_update_blocks(edit, fence=quad_backticks)) self.assertEqual(edits, [("foo.txt", "", "Tooooo\n")]) - #Test for shell script blocks with sh language identifier (issue #3785) + # Test for shell script blocks with sh language identifier (issue #3785) def test_find_original_update_blocks_with_sh_language_identifier(self): # https://github.com/Aider-AI/aider/issues/3785 edit = """ @@ -609,13 +587,13 @@ exit 0 # Check that the content contains the expected shell script elements result_content = edits[0][2] self.assertIn("#!/bin/bash", result_content) - self.assertIn("if [ \"$#\" -ne 1 ];", result_content) - self.assertIn("echo \"Usage: $0 \"", result_content) + self.assertIn('if [ "$#" -ne 1 ];', result_content) + self.assertIn('echo "Usage: $0 "', result_content) self.assertIn("exit 1", result_content) - self.assertIn("echo \"$1\"", result_content) + self.assertIn('echo "$1"', result_content) self.assertIn("exit 0", result_content) - #Test for C# code blocks with csharp language identifier + # Test for C# code blocks with csharp language identifier def test_find_original_update_blocks_with_csharp_language_identifier(self): edit = """ Here's a C# code change: @@ -631,12 +609,9 @@ Console.WriteLine("Hello, C# World!"); """ edits = list(eb.find_original_update_blocks(edit)) - search_text = "Console.WriteLine(\"Hello World!\");\n" - replace_text = "Console.WriteLine(\"Hello, C# World!\");\n" - self.assertEqual( - edits, - [("Program.cs", search_text, replace_text)] - ) + search_text = 'Console.WriteLine("Hello World!");\n' + replace_text = 'Console.WriteLine("Hello, C# World!");\n' + self.assertEqual(edits, [("Program.cs", search_text, replace_text)]) if __name__ == "__main__":