diff --git a/contact/utilities/utils.py b/contact/utilities/utils.py index d279c88..41f09d5 100644 --- a/contact/utilities/utils.py +++ b/contact/utilities/utils.py @@ -180,7 +180,8 @@ def build_reply_prefix(prefix: str, message: str) -> str: sender_text = re.sub(r"^(?:>>|<<)\s*(?:\[[^]]+\]\s*)?", "", sender_text) sender_match = re.search(r"(.+?)\s*:\s*$", sender_text) sender = sender_match.group(1).strip() if sender_match else "me" - excerpt = " ".join(message.replace("\x00", "").split())[:REPLY_EXCERPT_LENGTH] + message_without_reply_marker = re.sub(r"^]*>\s*", "", message.replace("\x00", "")) + excerpt = " ".join(message_without_reply_marker.split())[:REPLY_EXCERPT_LENGTH] return f" " diff --git a/tests/test_contact_ui.py b/tests/test_contact_ui.py index f092415..13c8dad 100644 --- a/tests/test_contact_ui.py +++ b/tests/test_contact_ui.py @@ -120,6 +120,14 @@ class ContactUiTests(unittest.TestCase): self.assertEqual(reply, " ") + def test_build_reply_prefix_does_not_nest_an_existing_reply_marker(self) -> None: + reply = contact_ui.build_reply_prefix( + "[06:27:25] >> xT1e: ", + " Woot indeed", + ) + + self.assertEqual(reply, " ") + def test_handle_ctrl_r_prefills_reply_for_message_at_cursor(self) -> None: ui_state.current_window = 1 ui_state.channel_list = ["Primary"]