From a0f03ab0cef278c82f808d732008590499f5f146 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Thu, 3 Aug 2023 15:39:46 -0300 Subject: [PATCH] regularize inputs --- aider/coders/editblock_coder.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/aider/coders/editblock_coder.py b/aider/coders/editblock_coder.py index c9fc872cf..3d4068988 100644 --- a/aider/coders/editblock_coder.py +++ b/aider/coders/editblock_coder.py @@ -45,12 +45,19 @@ The ORIGINAL block needs to be EXACTLY the same as the lines in {path} with noth return edited +def prep(content): + if not content.endswith("\n"): + content += "\n" + lines = content.splitlines(keepends=True) + return content, lines + + def replace_most_similar_chunk(whole, part, replace): """Best efforts to find the `part` lines in `whole` and replace them with `replace`""" - whole_lines = whole.splitlines(keepends=True) - part_lines = part.splitlines(keepends=True) - replace_lines = replace.splitlines(keepends=True) + whole, whole_lines = prep(whole) + part, part_lines = prep(part) + replace, replace_lines = prep(replace) # Try for a perfect match if part_lines in whole_lines: