From 0273b6b614bac623168d03e7f89f9e161274b468 Mon Sep 17 00:00:00 2001 From: "paseo-bot[bot]" <266920839+paseo-bot[bot]@users.noreply.github.com> Date: Sun, 15 Nov 2026 20:52:24 +0000 Subject: [PATCH] fix(app): end bare URLs at CJK and fullwidth punctuation (#9799) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A bare URL that md4c does not autolink is linked by the text-link pattern. That pattern stopped only at ASCII whitespace, quotes and sentence punctuation, so "https://a.com、https://b.com!" became one link, and "看这里:https://example.com/foo,还有" linked ",还有" too. Opening the link went to a URL ending in the encoded punctuation. CJK, fullwidth and typographic punctuation (、。,()【】「」“”…) now ends the URL. CJK letters in paths still stay in the link. Refs #9743 Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 --- .../src/components/markdown/renderer.test.ts | 28 +++++++++++++++++++ .../app/src/components/markdown/source.ts | 7 +++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/packages/app/src/components/markdown/renderer.test.ts b/packages/app/src/components/markdown/renderer.test.ts index 61d3e0e4d..e74d12a69 100644 --- a/packages/app/src/components/markdown/renderer.test.ts +++ b/packages/app/src/components/markdown/renderer.test.ts @@ -562,6 +562,34 @@ describe("bare URL sentence punctuation", () => { expect(tree.children?.[0]?.children?.[0]?.attributes?.url).toBe("https://example.com/a."); }, ); + + it.each([ + ["https://a.com、https://b.com!", ["https://a.com", "、", "https://b.com", "!"]], + ["https://a.com(说明)以及", ["https://a.com", "(说明)以及"]], + ["看这里:https://example.com/foo,还有", ["看这里:", "https://example.com/foo", ",还有"]], + ["(https://example.com/a)", ["(", "https://example.com/a", ")"]], + ["见【https://example.com/a】。", ["见【", "https://example.com/a", "】。"]], + ["“https://example.com/a”…", ["“", "https://example.com/a", "”…"]], + [ + "见https://zh.wikipedia.org/wiki/人工智能。", + ["见", "https://zh.wikipedia.org/wiki/人工智能", "。"], + ], + ])("ends a bare URL at CJK and typographic punctuation: %s", async (source, expected) => { + const prepared = prepareMarkdownSource(source); + const tree = recognizeTextLinks( + await parseMarkdown(prepared.render(), { latexMath: false }), + prepared.linkRecognition.text, + prepared.linkRecognition.inlineCode, + ); + const parts = (tree.children?.[0]?.children ?? []).map((node) => + node.type === "Link" ? String(node.attributes?.url) : String(node.content), + ); + expect(parts).toEqual(expected); + expect(toNativeLinkRecognition(prepared.linkRecognition).text).toMatchObject({ + isDisabled: false, + isDefault: false, + }); + }); }); it("requires workspace context for relative inline paths and escapes literal regex characters", () => { diff --git a/packages/app/src/components/markdown/source.ts b/packages/app/src/components/markdown/source.ts index ae3cdcba4..0a87dc016 100644 --- a/packages/app/src/components/markdown/source.ts +++ b/packages/app/src/components/markdown/source.ts @@ -37,9 +37,12 @@ function createTextPattern(path: string, forgeReferencePattern?: string): RegExp // Matches bare URLs that MD4C does not autolink, like single-label or bracketed hosts. // Quotes and unbalanced closing parentheses end the URL. Trailing sentence punctuation stays outside. -const URL_CHARACTER = String.raw`[^\s<>()"'\x60]`; +// CJK, fullwidth and typographic punctuation (、。,()【】「」“”…) also ends it; CJK letters do not. +const URL_BOUNDARY = + "\\u2018\\u2019\\u201C\\u201D\\u2026\\u3000-\\u3003\\u3008-\\u3011\\u3014-\\u301F\\uFF01-\\uFF0F\\uFF1A-\\uFF20\\uFF3B-\\uFF40\\uFF5B-\\uFF65"; +const URL_CHARACTER = String.raw`[^\s<>()"'\x60${URL_BOUNDARY}]`; const URL_GROUP = String.raw`\(${URL_CHARACTER}*\)`; -const BARE_URL = String.raw`https?://(?:${URL_CHARACTER}|${URL_GROUP})*(?:[^\s<>()"'\x60.,;:!?]|${URL_GROUP})`; +const BARE_URL = String.raw`https?://(?:${URL_CHARACTER}|${URL_GROUP})*(?:[^\s<>()"'\x60.,;:!?${URL_BOUNDARY}]|${URL_GROUP})`; const TEXT_PATTERN = createTextPattern(PROSE_PATH); // One entry per distinct workspace forge remote; reuse keeps the engine's regex identity stable.