Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
markdown: Use \p{White_Space} equivalent for linkifier boundaries.
Alex Vandiver70b20e9d2bfe
diff --git a/zerver/lib/markdown/__init__.py b/zerver/lib/markdown/__init__.pyindex 009abcf5b85..a4c0ce4c6c5 100644--- a/zerver/lib/markdown/__init__.py+++ b/zerver/lib/markdown/__init__.py@@ -1812,10 +1812,18 @@ def prepare_linkifier_pattern(source: str) -> str:whitespace, or opening delimiters, won't match if there are wordcharacters directly after, and saves what was matched asOUTER_CAPTURE_GROUP."""++ # This NEL character (0x85) is interpolated via a variable,+ # because r"" strings cannot use backslash escapes.+ next_line = "\u0085"++ # We use an extended definition of 'whitespace' which is+ # equivalent to \p{White_Space} -- since \s in re2 only matches+ # ASCII spaces, and re2 does not support \p{White_Space}.regex = rf"""(?P<{BEFORE_CAPTURE_GROUP}>^ |- \s |+ \s | {next_line} | \pZ |['"\(,:<])(?P<{OUTER_CAPTURE_GROUP}>@@ -1828,7 +1836,8 @@ def prepare_linkifier_pattern(source: str) -> str:"""# Strip out the spaces and newlines added to make the above# legible -- re2 does not have the equivalent of the /x modifier- # that does this automatically.+ # that does this automatically. Note that we are careful to not+ # strip _whitespace_, which would strip the literal \u0085 out.return regex.replace(" ", "").replace("\n", "")diff --git a/zerver/tests/test_markdown.py b/zerver/tests/test_markdown.pyindex ebae8e2c4dd..48b1a770a07 100644--- a/zerver/tests/test_markdown.py+++ b/zerver/tests/test_markdown.py@@ -1307,6 +1307,7 @@ class MarkdownTest(ZulipTestCase):assert_conversion("Hello #123World", False)assert_conversion("Hello#123 World", False)assert_conversion("Hello#123World", False)+ assert_conversion("Hello\u00A0#123\u00A0World")# Ideally, these should be converted, but Markdown doesn't# handle word boundary detection in languages that don't use# whitespace for that correctly yet.