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 autolinking of URLs preceded by multibyte characters.

Nithyaraj Mudhaliyar53896e929890
diff --git a/zerver/lib/markdown/__init__.py b/zerver/lib/markdown/__init__.py
index 8ca3065befb..7565bbe1251 100644
--- a/zerver/lib/markdown/__init__.py
+++ b/zerver/lib/markdown/__init__.py
@@ -259,8 +259,9 @@ def get_web_link_regex() -> Pattern[str]:
nested_paren_chunk %= (inner_paren_contents,)
file_links = r"| (?:file://(/[^/ ]*)+/?)" if settings.ENABLE_FILE_LINKS else r""
+
REGEX = rf"""
- (?<![^\s'"\(,:<]) # Start after whitespace or specified chars
+ (?<![^\s'"\(,:<\u0080-\U0010FFFF]) # Start after whitespace, specified chars, or multibyte chars
# (Double-negative lookbehind to allow start-of-string)
(?P<url> # Main group
(?:(?: # Domain part
diff --git a/zerver/tests/fixtures/markdown_test_cases.json b/zerver/tests/fixtures/markdown_test_cases.json
index bb5eec02ae8..b4bcce79972 100644
--- a/zerver/tests/fixtures/markdown_test_cases.json
+++ b/zerver/tests/fixtures/markdown_test_cases.json
@@ -1492,6 +1492,21 @@
"asanadesktop://task/123456789",
"<p>%s</p>",
"asanadesktop://task/123456789"
+ ],
+ [
+ "日本語https://google.com",
+ "<p>日本語<a href=\"https://google.com\">https://google.com</a></p>",
+ "https://google.com"
+ ],
+ [
+ "你好https://google.com",
+ "<p>你好<a href=\"https://google.com\">https://google.com</a></p>",
+ "https://google.com"
+ ],
+ [
+ "Приветhttps://google.com",
+ "<p>Привет<a href=\"https://google.com\">https://google.com</a></p>",
+ "https://google.com"
]
]
}