Skip to content

strip_quoted_wrapping() incorrectly detects quoted wrappings #4093 #4094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions aider/coders/editblock_coder.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,15 +346,17 @@ def strip_quoted_wrapping(res, fname=None, fence=DEFAULT_FENCE):
if not res:
return res

res = res.splitlines()
res_lines = res.splitlines()

if fname and res[0].strip().endswith(Path(fname).name):
res = res[1:]
if fname and len(res_lines) > 1 and res_lines[0].strip().endswith(Path(fname).name):
res_lines = res_lines[1:]

if res[0].startswith(fence[0]) and res[-1].startswith(fence[1]):
res = res[1:-1]
if res_lines[0].startswith(fence[0]) and res_lines[-1].startswith(fence[1]):
res_lines = res_lines[1:-1]
else:
return res # Directly return the original string if it doesn't need to be stripped

res = "\n".join(res)
res = "\n".join(res_lines)
if res and res[-1] != "\n":
res += "\n"

Expand Down
12 changes: 12 additions & 0 deletions tests/basic/test_editblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ def test_strip_quoted_wrapping_no_wrapping(self):
result = eb.strip_quoted_wrapping(input_text)
self.assertEqual(result, expected_output)

def test_strip_quoted_wrapping_filename_only(self):
input_text = "filename.ext\n"
expected_output = "filename.ext\n"
result = eb.strip_quoted_wrapping(input_text, "filename.ext")
self.assertEqual(result, expected_output)

def test_strip_quoted_wrapping_filename_ending(self):
input_text = "Line that ends with filename.ext\nA second line"
expected_output = "Line that ends with filename.ext\nA second line"
result = eb.strip_quoted_wrapping(input_text, "filename.ext")
self.assertEqual(result, expected_output)

def test_find_original_update_blocks(self):
edit = """
Here's the change:
Expand Down
5 changes: 3 additions & 2 deletions tests/basic/test_run_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@


def test_run_cmd_echo():
command = "echo Hello, World!"
# echo can work the same in both Linux and Windows if only echoing one word
command = "echo Hello!"
exit_code, output = run_cmd(command)

assert exit_code == 0
assert output.strip() == "Hello, World!"
assert output.strip() == "Hello!"