mirror of https://github.com/zulip/zulip.git
markdown: Fix URL link topic skipping query.
When searching for links inside a topic name, the question mark (?) was used to split the topic. If a URL had a query after the URL (e.g., "?foo=bar"), then the query was trimmed from the URL. Removing the question mark from `basic_link_splitter` is sufficient to fix this issue. The `get_web_link_regex` function then removes the trailing punctuation if any, including literal question marks. Fixes #26368.
This commit is contained in:
parent
8c91c91d86
commit
732ad89f3d
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue