From c10ca453d9c3722100e6d1a6be7f205ccc38905e Mon Sep 17 00:00:00 2001 From: Robert Alonso <17463757+rgalonso@users.noreply.github.com> Date: Thu, 14 Nov 2024 20:40:49 +0000 Subject: [PATCH] fix: handle issue title line with trailing whitespace Fix a regression that was accidentally introduced with v5.1.2 which could cause an issue URL to not be successfully added to the source file when dealing with a CRLF (Windows-style line endings) file on Linux. Partially addresses GitHub issue #245 --- TodoParser.py | 2 +- main.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/TodoParser.py b/TodoParser.py index 42173d0..6995aed 100644 --- a/TodoParser.py +++ b/TodoParser.py @@ -547,7 +547,7 @@ class TodoParser(object): comment = comment.strip() pre_marker_length = original_comment.find(comment) else: - comment_segments = re.search(fr'^(.*?)({marker["pattern"]})(\s*)(.*)', comment) + comment_segments = re.search(fr'^(.*?)({marker["pattern"]})(\s*)(.*?)\s*$', comment) if comment_segments: pre_marker_text, _, post_marker_whitespace, comment = comment_segments.groups() pre_marker_length = len(pre_marker_text) diff --git a/main.py b/main.py index 845d82b..d687cb4 100644 --- a/main.py +++ b/main.py @@ -76,7 +76,7 @@ def process_diff(diff, client=Client(), insert_issue_urls=False, parser=TodoPars if line_number < len(file_lines): # Duplicate the line to retain the comment syntax. old_line = file_lines[line_number] - remove = fr'(?i:{re.escape(raw_issue.identifier)}).*{re.escape(raw_issue.title)}' + remove = fr'(?i:{re.escape(raw_issue.identifier)}).*{re.escape(raw_issue.title)}.*?(\r|\r\n|\n)?$' insert = f'Issue URL: {client.get_issue_url(new_issue_number)}' new_line = re.sub('^.*'+remove, raw_issue.prefix + insert, old_line) # make sure the above operation worked as intended