mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 05:23:35 +00:00
slack_regex: Update Slack regex handle multiline strings.
This prep commit modifies the Slack text regex in `slack_message_conversion.py` to use the `re.MULTILINE` flag capture formatted strings that are adjacent to newline or end of line. These kinds of strings are likely not uncommon to be generated by Slack exporter itself and our Slack message block and attachment formatters (`render_blocks` and `render_attachments`) also produces them. This also fixes Slack webhook integration's `test_message_with_complex_formatted_texts` which was previously expecting false output. Fixes part of #30827.
This commit is contained in:
@@ -183,7 +183,7 @@ def convert_markdown_syntax(text: str, pattern: str, zulip_keyword: str) -> str:
|
||||
+ match.group(6)
|
||||
)
|
||||
|
||||
return regex.sub(pattern, replace_slack_format, text, flags=re.VERBOSE)
|
||||
return regex.sub(pattern, replace_slack_format, text, flags=re.VERBOSE | re.MULTILINE)
|
||||
|
||||
|
||||
def convert_slack_workspace_mentions(text: str) -> str:
|
||||
|
||||
@@ -89,6 +89,16 @@
|
||||
"name": "unicode_quotes",
|
||||
"input": "«~strike~» 「*bold*」 ❰_italic_❱",
|
||||
"conversion_output": "«~~strike~~» 「**bold**」 ❰*italic*❱"
|
||||
},
|
||||
{
|
||||
"name": "new_line_test",
|
||||
"input": "\n*abc*\n_helo_\n~stike~\n",
|
||||
"conversion_output": "\n**abc**\n*helo*\n~~stike~~\n"
|
||||
},
|
||||
{
|
||||
"name": "zero_width_identical_bold_matches_test",
|
||||
"input": "*foo*\n*foo*\n*foo*",
|
||||
"conversion_output": "**foo**\n**foo**\n**foo**"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -271,7 +271,7 @@ class SlackWebhookTests(WebhookTestCase):
|
||||
)
|
||||
|
||||
def test_message_with_complex_formatted_texts(self) -> None:
|
||||
message_body = "this is text messages with overlapping formatting\n_**bold with italic**_\n~**bold with strike through**~\n~*italic with strike through*~\n~***all three***~"
|
||||
message_body = "this is text messages with overlapping formatting\n***bold with italic***\n~~**bold with strike through**~~\n~~*italic with strike through*~~\n~~***all three***~~"
|
||||
expected_message = EXPECTED_MESSAGE.format(user=USER, message=message_body)
|
||||
self.check_webhook(
|
||||
"message_with_complex_formatted_texts",
|
||||
|
||||
Reference in New Issue
Block a user