mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-25 14:55:00 +00:00
fix: Handle filenames starting with fences or triple backticks correctly
This commit is contained in:
parent
c6ce871700
commit
5e210c700d
2 changed files with 16 additions and 37 deletions
|
@ -414,11 +414,15 @@ def strip_filename(filename, fence):
|
||||||
start_fence = fence[0]
|
start_fence = fence[0]
|
||||||
if filename.startswith(start_fence):
|
if filename.startswith(start_fence):
|
||||||
candidate = filename[len(start_fence) :]
|
candidate = filename[len(start_fence) :]
|
||||||
if candidate and "." in candidate:
|
if candidate and ("." in candidate or "/" in candidate):
|
||||||
return candidate
|
return candidate
|
||||||
|
return
|
||||||
|
|
||||||
if filename.startswith(triple_backticks):
|
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.rstrip(":")
|
||||||
filename = filename.lstrip("#")
|
filename = filename.lstrip("#")
|
||||||
|
|
|
@ -108,29 +108,6 @@ Hope you like it!
|
||||||
edits = list(eb.find_original_update_blocks(edit))
|
edits = list(eb.find_original_update_blocks(edit))
|
||||||
self.assertEqual(edits, [("foo.txt", "Two\n", "Tooooo\n")])
|
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
|
|
||||||
</%s>
|
|
||||||
|
|
||||||
Hope you like it!
|
|
||||||
""" % (source, source)
|
|
||||||
|
|
||||||
fence = ("<%s>" % source, "</%s>" % 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):
|
def test_find_original_update_blocks_quote_below_filename(self):
|
||||||
edit = """
|
edit = """
|
||||||
Here's the change:
|
Here's the change:
|
||||||
|
@ -181,10 +158,11 @@ Tooooo
|
||||||
|
|
||||||
|
|
||||||
oops!
|
oops!
|
||||||
|
>>>>>>> REPLACE
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with self.assertRaises(ValueError) as cm:
|
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))
|
self.assertIn("filename", str(cm.exception))
|
||||||
|
|
||||||
def test_find_original_update_blocks_no_final_newline(self):
|
def test_find_original_update_blocks_no_final_newline(self):
|
||||||
|
@ -609,10 +587,10 @@ exit 0
|
||||||
# Check that the content contains the expected shell script elements
|
# Check that the content contains the expected shell script elements
|
||||||
result_content = edits[0][2]
|
result_content = edits[0][2]
|
||||||
self.assertIn("#!/bin/bash", result_content)
|
self.assertIn("#!/bin/bash", result_content)
|
||||||
self.assertIn("if [ \"$#\" -ne 1 ];", result_content)
|
self.assertIn('if [ "$#" -ne 1 ];', result_content)
|
||||||
self.assertIn("echo \"Usage: $0 <argument>\"", result_content)
|
self.assertIn('echo "Usage: $0 <argument>"', result_content)
|
||||||
self.assertIn("exit 1", 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)
|
self.assertIn("exit 0", result_content)
|
||||||
|
|
||||||
# Test for C# code blocks with csharp language identifier
|
# Test for C# code blocks with csharp language identifier
|
||||||
|
@ -631,12 +609,9 @@ Console.WriteLine("Hello, C# World!");
|
||||||
"""
|
"""
|
||||||
|
|
||||||
edits = list(eb.find_original_update_blocks(edit))
|
edits = list(eb.find_original_update_blocks(edit))
|
||||||
search_text = "Console.WriteLine(\"Hello World!\");\n"
|
search_text = 'Console.WriteLine("Hello World!");\n'
|
||||||
replace_text = "Console.WriteLine(\"Hello, C# World!\");\n"
|
replace_text = 'Console.WriteLine("Hello, C# World!");\n'
|
||||||
self.assertEqual(
|
self.assertEqual(edits, [("Program.cs", search_text, replace_text)])
|
||||||
edits,
|
|
||||||
[("Program.cs", search_text, replace_text)]
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue