💚 End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[space][web] Fix Unicode handling in message links
Anand Baburajanfde410749bbd
diff --git a/web/apps/space/src/components/MessageText.tsx b/web/apps/space/src/components/MessageText.tsxindex 58b1c93018..5325fd012f 100644--- a/web/apps/space/src/components/MessageText.tsx+++ b/web/apps/space/src/components/MessageText.tsx@@ -1,7 +1,7 @@import React from "react";const messageURLPattern =- /\bhttps?:\/\/[^\s<>"']+|(?<![\w@/.:+-])(?:[a-z\d](?:[a-z\d-]*[a-z\d])?\.)+[a-z]{2,}(?![\w@-])(?::\d+)?(?:[/?#][^\s<>"']*)?/gi;+ /\bhttps?:\/\/[^\s<>"']+|(?<![\p{L}\p{M}\p{N}_@/.:+-])(?:[a-z\d](?:[a-z\d-]*[a-z\d])?\.)+[a-z]{2,}(?![\p{L}\p{M}\p{N}_@-]|\.[\p{L}\p{M}\p{N}_-])(?::\d+)?(?:[/?#][^\s<>"']*)?/giu;export const SpaceMessageText: React.FC<{ text: string }> = ({ text }) => {const content: React.ReactNode[] = [];@@ -9,7 +9,7 @@ export const SpaceMessageText: React.FC<{ text: string }> = ({ text }) => {for (const match of text.matchAll(messageURLPattern)) {let value = match[0];- while (/[.,!?;:)\]}]$/.test(value)) {+ while (/[.,!?;:)\]}。,、!?;:…’”]$/.test(value)) {if (value.endsWith(")") &&value.split("(").length >= value.split(")").lengthdiff --git a/web/apps/space/tests/message-text.test.ts b/web/apps/space/tests/message-text.test.tsindex 0566e06045..769bf7adae 100644--- a/web/apps/space/tests/message-text.test.ts+++ b/web/apps/space/tests/message-text.test.ts@@ -77,3 +77,36 @@ test("punctuation around links stays outside the link", () => {expect(html).toContain(">https://ente.io</a>.), then ");expect(html).toMatch(/>ente\.io<\/a>!$/);});++test.each([+ "bücher.de",+ "bu\u0308cher.de",+ "bücher.example.com",+ "example.cöm",+ "example.com.中国",+ "例example.com",+])("internationalized bare domains stay entirely unlinked: %s", (domain) => {+ const html = renderMessage(`See ${domain} or ente.io`);+ expect(html.startsWith(`See ${domain} or <a `)).toBe(true);+ expect(html).toContain('href="https://ente.io"');+});++test.each(["。", ",", "、", "!", "?", ";", ":", "…", "。”"])(+ "non-ASCII sentence punctuation stays outside links: %s",+ (punctuation) => {+ const html = renderMessage(+ `See https://example.com/path${punctuation}`,+ );+ expect(html).toContain('href="https://example.com/path"');+ expect(+ html.endsWith(`>https://example.com/path</a>${punctuation}`),+ ).toBe(true);+ },+);++test("explicit URLs preserve internationalized domains and Unicode paths", () => {+ const url = "https://bücher.de/資料/日本語?q=%E3%80%82";+ const html = renderMessage(url);+ expect(html).toContain(`href="${url}"`);+ expect(html).toContain(`>${url}</a>`);+});