From f9fca5b46952f3238531ea33019ff64b62341ede Mon Sep 17 00:00:00 2001 From: Prakhar Pratyush Date: Fri, 31 May 2024 00:02:52 +0530 Subject: [PATCH] remove_single_newlines: Fix regex to parse list syntax correctly. Earlier, the 'remove_single_newlines' function wasn't working correctly when '\n' was followed by asterix, hyphen, or number. Specifically, they were not added as a syntax for ordered or unordered list in markdown. For example, see the workaround fix in 330439a83b7c9d01bfc608a7e82b427f53bae164. This commit updates the function to replace '\n' with ' ', when "\n" is not preceded by "\n" and not followed by: * Another newline (\n) * A hyphen followed by a space * An asterisk followed by a space * A number followed by a dot and a space We won't have to do fixes like 330439a83b7c9d01bfc608a7e82b427f53bae164 in the future. --- zerver/lib/message.py | 2 +- .../tests/test_zulip_update_announcements.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/zerver/lib/message.py b/zerver/lib/message.py index 3027d87bb7..6cbc9b8533 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"(? None: with mock.patch( "zerver.lib.zulip_update_announcements.zulip_update_announcements",