Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
slack_regex: Fix overlapping capture groups.
PieterCKc018911c5bd3
diff --git a/zerver/data_import/slack_message_conversion.py b/zerver/data_import/slack_message_conversion.pyindex cb9d7033e97..ffb6ceae3cc 100644--- a/zerver/data_import/slack_message_conversion.py+++ b/zerver/data_import/slack_message_conversion.py@@ -69,7 +69,7 @@ SLACK_STRIKETHROUGH_REGEX = r"""# Skip @ and \# Skip opening brackets & opening quote (\p{Pi}\p{Ps})(?![~`@\\\p{Pi}\p{Ps}])- [\p{P}\p{Zs}\p{S}]|$+ (?=[\p{P}\p{Zs}\p{S}]|$))"""SLACK_ITALIC_REGEX = r"""@@ -84,7 +84,7 @@ SLACK_ITALIC_REGEX = r"""(\_)((?![_`@\\\p{Pi}\p{Ps}])- [\p{P}\p{Zs}\p{S}]|$+ (?=[\p{P}\p{Zs}\p{S}]|$))"""SLACK_BOLD_REGEX = r"""@@ -99,7 +99,7 @@ SLACK_BOLD_REGEX = r"""(\*)((?![*`@\\\p{Pi}\p{Ps}])- [\p{P}\p{Zs}\p{S}]|$+ (?=[\p{P}\p{Zs}\p{S}]|$))"""@@ -174,7 +174,7 @@ def convert_markdown_syntax(text: str, pattern: str, zulip_keyword: str) -> str:"""def replace_slack_format(match: regex.Match[str]) -> str:- return match.group(1) + zulip_keyword + match.group(3) + zulip_keyword + match.group(5)+ return match.group(1) + zulip_keyword + match.group(3) + zulip_keywordreturn regex.sub(pattern, replace_slack_format, text, flags=re.VERBOSE | re.MULTILINE)diff --git a/zerver/tests/fixtures/slack_message_conversion.json b/zerver/tests/fixtures/slack_message_conversion.jsonindex ea3fcd6ba80..450ca19bb77 100644--- a/zerver/tests/fixtures/slack_message_conversion.json+++ b/zerver/tests/fixtures/slack_message_conversion.json@@ -104,6 +104,11 @@"name": "format_emoji_test","input": "*1️⃣ bold* some _1️⃣ italic_ word ~1️⃣ strike~","conversion_output": "**1️⃣ bold** some *1️⃣ italic* word ~~1️⃣ strike~~"+ },+ {+ "name": "overlapping_capture_group_test",+ "input": "*foo* *baz* *bar*",+ "conversion_output": "**foo** **baz** **bar**"}]}diff --git a/zerver/webhooks/slack/tests.py b/zerver/webhooks/slack/tests.pyindex a9b82063e53..b1e73256378 100644--- a/zerver/webhooks/slack/tests.py+++ b/zerver/webhooks/slack/tests.py@@ -281,7 +281,7 @@ class SlackWebhookTests(WebhookTestCase):)def test_message_with_complex_formatted_mentions(self) -> None:- message_body = "@**John Doe** **#general** ~~***@**all*****~"+ message_body = "@**John Doe** **#general** ~~***@**all*****~~"expected_message = EXPECTED_MESSAGE.format(user=USER, message=message_body)self.check_webhook("message_with_complex_formatted_mentions",