Repository: zulip/zulip

Issue:
Open link button in topic skips part of link
Clicking open link with a topic such as `https://client.atomontage.app/view?m=8GvRSx5LVIXSQhQSEChhx` will open just `https://client.atomontage.app/view` 

**Zulip Server and web app version:**

- [ ] Zulip Cloud (`*.zulipchat.com`)
- [x] Zulip Server 7.0+
- [ ] Zulip Server 6.0+
- [ ] Zulip Server 5.0 or older
- [ ] Other or not sure



Discussion:
Hello @zulip/server-markdown members, this issue was labeled with the "area: markdown" label, so you may want to check it out!

<!-- areaLabelAddition -->

I started a conversation about this issue in the [Zulip development community](https://zulip.com/development-community/) here: https://chat.zulip.org/#narrow/stream/9-issues/topic/URL.20link.20for.20topic.20name.20not.20exact.20match.2C.20.2326368/near/1617354
Hi @laurynmm ,
Can I work on this issue based on the solution in [community chat](https://chat.zulip.org/#narrow/stream/9-issues/topic/URL.20link.20for.20topic.20name.20not.20exact.20match.2C.20.2326368/near/1624943) ?
Btw were also getting long links truncated due to the character limit of topics, perhaps the open link button could use the full link anyways 
> Btw were also getting long links truncated due to the character limit of topics, perhaps the open link button could use the full link anyways

sure
can you please assign this issue to me?
@mkster - Topics are limited in length (I'm not sure if this is documented in the help center, but it's in the API documentation e.g. here for the [topic parameter](https://zulip.com/api/send-message#parameter-topic) for sending a message). So, the server would have no way to know what the full link is as it's just linking the text of the topic. For your use case, would it be possible to use [custom linkifiers](https://zulip.com/help/add-a-custom-linkifier) in your topics?

@sayyedarib - Thanks for your interest in this issue. Let me follow-up on on the conversation on CZO and go from there. I don't think the aspect of topics being limited in length was addressed.
aha great I didnt know about linkifiers 

Resolving patch:
diff --git a/zerver/lib/markdown/__init__.py b/zerver/lib/markdown/__init__.py
--- 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:


Test patch:
diff --git a/zerver/tests/test_markdown.py b/zerver/tests/test_markdown.py
--- a/zerver/tests/test_markdown.py
+++ b/zerver/tests/test_markdown.py
@@ -1160,6 +1160,36 @@ def test_links_in_topic_name(self) -> None:
             ],
         )
 
+        # 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: