Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
remove_single_newlines: Fix regex to parse list syntax correctly.
Prakhar Pratyushf9fca5b46952
diff --git a/zerver/lib/message.py b/zerver/lib/message.pyindex 3027d87bb79..6cbc9b8533d 100644--- a/zerver/lib/message.py+++ b/zerver/lib/message.py@@ -1435,4 +1435,4 @@ def set_visibility_policy_possible(user_profile: UserProfile, message: Message)def remove_single_newlines(content: str) -> str:content = content.strip("\n")- return re.sub(r"(?<!\n)\n(?![\n0-9*-])", " ", content)+ return re.sub(r"(?<!\n)\n(?!\n|[-*] |[0-9]+\. )", " ", content)diff --git a/zerver/tests/test_zulip_update_announcements.py b/zerver/tests/test_zulip_update_announcements.pyindex e8c23d6d112..c9d5cb2743d 100644--- a/zerver/tests/test_zulip_update_announcements.py+++ b/zerver/tests/test_zulip_update_announcements.py@@ -313,6 +313,25 @@ class ZulipUpdateAnnouncementsTest(ZulipTestCase):expected_output = "- This is a bullet.\n- This is another bullet.\n\n1. This is a list\n1. This is more list."self.assertEqual(remove_single_newlines(input_text), expected_output)+ # Asterisks after newline for bold.+ input_text = "* This is a bullet.\n**word in bold** on the same line.\n* Another bullet."+ expected_output = (+ "* This is a bullet. **word in bold** on the same line.\n* Another bullet."+ )+ self.assertEqual(remove_single_newlines(input_text), expected_output)++ # Digit after newline.+ input_text = "1. This is a numbered list.\n2. Second list element.\n3.5 is a decimal.\n3. Third list element."+ expected_output = "1. This is a numbered list.\n2. Second list element. 3.5 is a decimal.\n3. Third list element."+ self.assertEqual(remove_single_newlines(input_text), expected_output)++ # Hyphen after newline.+ input_text = "- This is a list.\n-C-C- organic molecule structure.\n- Another list element."+ expected_output = (+ "- This is a list. -C-C- organic molecule structure.\n- Another list element."+ )+ self.assertEqual(remove_single_newlines(input_text), expected_output)+def test_zulip_updates_for_realm_imported_from_other_product(self) -> None:with mock.patch("zerver.lib.zulip_update_announcements.zulip_update_announcements",