diff --git a/zerver/lib/markdown/__init__.py b/zerver/lib/markdown/__init__.py index 21b6f9ac7c..4808511222 100644 --- a/zerver/lib/markdown/__init__.py +++ b/zerver/lib/markdown/__init__.py @@ -2284,7 +2284,7 @@ def make_md_engine(linkifiers_key: int, email_gateway: bool) -> None: # Split the topic name into multiple sections so that we can easily use # our common single link matching regex on it. -basic_link_splitter = re.compile(r"[ !;\?\),\'\"]") +basic_link_splitter = re.compile(r"[ !;\),\'\"]") def percent_escape_format_string(format_string: str) -> str: diff --git a/zerver/tests/test_markdown.py b/zerver/tests/test_markdown.py index 979a29f56b..c75f129c50 100644 --- a/zerver/tests/test_markdown.py +++ b/zerver/tests/test_markdown.py @@ -1160,6 +1160,36 @@ class MarkdownTest(ZulipTestCase): ], ) + # Query strings in a URL should be included in the link. + msg.set_topic_name("https://google.com/test?foo=bar") + converted_topic = topic_links(realm.id, msg.topic_name()) + self.assertEqual( + converted_topic, + [ + { + "url": "https://google.com/test?foo=bar", + "text": "https://google.com/test?foo=bar", + }, + ], + ) + # But question marks at the end of sentence are not part of the URL. + msg.set_topic_name("Have you seen github.com/zulip?") + converted_topic = topic_links(realm.id, msg.topic_name()) + self.assertEqual( + converted_topic, + [ + {"url": "https://github.com/zulip", "text": "github.com/zulip"}, + ], + ) + msg.set_topic_name("Do you like https://example.com? I love it.") + converted_topic = topic_links(realm.id, msg.topic_name()) + self.assertEqual( + converted_topic, + [ + {"url": "https://example.com", "text": "https://example.com"}, + ], + ) + def check_add_linkifiers( self, linkifiers: List[RealmFilter], expected_linkifier_reprs: List[str] ) -> None: