Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

markdown: Fix linkification of URLs starting with query params.

Nithyaraj Mudhaliyar98e14a644f3e
diff --git a/zerver/lib/markdown/__init__.py b/zerver/lib/markdown/__init__.py
index b2f1114b293..3edc4737aa1 100644
--- a/zerver/lib/markdown/__init__.py
+++ b/zerver/lib/markdown/__init__.py
@@ -262,8 +262,10 @@ def get_web_link_regex() -> Pattern[str]:
(?:{tlds}) # TLDs
)
)
- (?:/ # A path, beginning with /
- {nested_paren_chunk} # zero-to-6 sets of paired parens
+ (?:
+ (?:/ {nested_paren_chunk} ) # A path, beginning with /; zero-to-6 sets of paired parens
+ |
+ (?: \? (?![)\"\s]|\Z) {nested_paren_chunk} ) # Query starting with ? (must not be trailing punctuation)
)?) # Path is optional
| (?:[\w.-]+\@[\w.-]+\.[\w]+) # Email is separate, since it can't have a path
{file_links} # File path start with file:///, enable by setting ENABLE_FILE_LINKS=True
diff --git a/zerver/tests/fixtures/markdown_test_cases.json b/zerver/tests/fixtures/markdown_test_cases.json
index a956ce1b2c8..191d086cc95 100644
--- a/zerver/tests/fixtures/markdown_test_cases.json
+++ b/zerver/tests/fixtures/markdown_test_cases.json
@@ -1437,6 +1437,26 @@
"quora http://generate.quora.net/render?width=700&from=-4hours&until=now&height=400&bgcolor=black&lineMode=connected&title=arb%20hint%20status&target=alias(ans.hintland.hand.arb.enhint_rate%2C%22enhint%20rate%22)&target=alias(ans.hintland.hand.arb.unhint_rate%2C%22unhint%20rate%22)&target=alias(ans.hintland.hand.arb.size%2C%22hint%20size%22)&target=alias(scale(ans.vagabond.dingarb_cube_count%2C10000)%2C%22cube%20count%20x%2010K%22)&target=alias(scale(hnumbers.time.ding.gegevens.query.count%2C10)%2C%22ding%20gegevens%20query%20count%20x%2010%22)&fgcolor=white&uniq=0.44046106841415167",
"<p>quora %s</p>",
"http://generate.quora.net/render?width=700&amp;from=-4hours&amp;until=now&amp;height=400&amp;bgcolor=black&amp;lineMode=connected&amp;title=arb%20hint%20status&amp;target=alias(ans.hintland.hand.arb.enhint_rate%2C%22enhint%20rate%22)&amp;target=alias(ans.hintland.hand.arb.unhint_rate%2C%22unhint%20rate%22)&amp;target=alias(ans.hintland.hand.arb.size%2C%22hint%20size%22)&amp;target=alias(scale(ans.vagabond.dingarb_cube_count%2C10000)%2C%22cube%20count%20x%2010K%22)&amp;target=alias(scale(hnumbers.time.ding.gegevens.query.count%2C10)%2C%22ding%20gegevens%20query%20count%20x%2010%22)&amp;fgcolor=white&amp;uniq=0.44046106841415167"
+ ],
+ [
+ "Check this: https://podcasts.google.com?feed=abc",
+ "<p>Check this: %s</p>",
+ "https://podcasts.google.com?feed=abc"
+ ],
+ [
+ "Is this https://google.com?",
+ "<p>Is this %s?</p>",
+ "https://google.com"
+ ],
+ [
+ "New logic inside parens: (see https://podcasts.google.com?feed=abc)",
+ "<p>New logic inside parens: (see <a href=\"https://podcasts.google.com?feed=abc\">https://podcasts.google.com?feed=abc</a>)</p>",
+ "(see https://podcasts.google.com?feed=abc)"
+ ],
+ [
+ "New logic with trailing dot: Go to https://podcasts.google.com?feed=abc.",
+ "<p>New logic with trailing dot: Go to <a href=\"https://podcasts.google.com?feed=abc\">https://podcasts.google.com?feed=abc</a>.</p>",
+ "Go to https://podcasts.google.com?feed=abc."
]
]
}