From 92e091f5a63fe5140a0a21d991257fc7222b1238 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Fri, 12 May 2023 13:30:39 -0700 Subject: [PATCH] fix bug if ORIG/UPD block is missing trailing newline; added test --- aider/utils.py | 20 ++++---------------- tests/test_utils.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/aider/utils.py b/aider/utils.py index 42f0195a1..18e109760 100644 --- a/aider/utils.py +++ b/aider/utils.py @@ -129,22 +129,6 @@ def show_messages(messages, title): print(role, line) -pattern = re.compile( - # Optional: Matches the start of a code block (e.g., ```python) and any following whitespace - r"(^```\S*\s*)?" - # Matches the file path - r"^(\S+)\s*" - # Optional: Matches the end of a code block (e.g., ```) and any following whitespace - r"(^```\S*\s*)?" - # Matches the start of the ORIGINAL section and captures its content - r"^<<<<<<< ORIGINAL\n(.*?\n?)" - # Matches sep between ORIGINAL and UPDATED sections, captures UPDATED content - r"^=======\n(.*?)" - # Matches the end of the UPDATED section - r"^>>>>>>> UPDATED", - re.MULTILINE | re.DOTALL, -) - ORIGINAL = "<<<<<<< ORIGINAL" DIVIDER = "=======" UPDATED = ">>>>>>> UPDATED" @@ -155,6 +139,10 @@ split_re = re.compile(r"^((?:" + separators + r")[ ]*\n)", re.MULTILINE | re.DOT def find_original_update_blocks(content): + # make sure we end with a newline, otherwise the regex will miss <>>>>>> UPDATED + +aider/coder.py +<<<<<<< ORIGINAL + self.io.tool_error("Malformed ORIGINAL/UPDATE blocks, retrying...") + self.io.tool_error(err) +======= + self.io.tool_error("Malformed ORIGINAL/UPDATE blocks, retrying...") + self.io.tool_error(str(err)) +>>>>>>> UPDATED + +aider/coder.py +<<<<<<< ORIGINAL + self.console.print("[red]Unable to get commit message from gpt-3.5-turbo. Use /commit to try again.\n") +======= + self.io.tool_error("Unable to get commit message from gpt-3.5-turbo. Use /commit to try again.") +>>>>>>> UPDATED + +aider/coder.py +<<<<<<< ORIGINAL + self.console.print("[red]Skipped commmit.") +======= + self.io.tool_error("Skipped commmit.") +>>>>>>> UPDATED""" + + # Should not raise a ValueError + list(utils.find_original_update_blocks(edit)) + if __name__ == "__main__": unittest.main()