Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix: address review — keep Unicode URL path and IDN
Chris7146c6c3af06
diff --git a/apps/desktop/src/renderer/__tests__/remarkTruncateCjkUrls.test.ts b/apps/desktop/src/renderer/__tests__/remarkTruncateCjkUrls.test.tsindex 8658fe7f7e..da7005bc12 100644--- a/apps/desktop/src/renderer/__tests__/remarkTruncateCjkUrls.test.ts+++ b/apps/desktop/src/renderer/__tests__/remarkTruncateCjkUrls.test.ts@@ -160,6 +160,15 @@ describe('remarkTruncateCjkUrls', () => {expect(tail.value).toBe('(无 @)');});+ it('URL 路径里的汉字保留:https://example.com/路径', () => {+ const tree = autolinkTree('https://example.com/路径');+ transform(tree);+ const para = tree.children[0] as Paragraph;+ const link = para.children[0] as Link;+ expect(link.url).toBe('https://example.com/路径');+ expect(para.children).toHaveLength(1);+ });+it('URL + 直接跟中文文字:https://example.com/path这是说明', () => {const tree = autolinkTree('https://example.com/path这是说明');transform(tree);diff --git a/apps/desktop/src/renderer/__tests__/userMessageLinkify.test.ts b/apps/desktop/src/renderer/__tests__/userMessageLinkify.test.tsindex 0bcf725015..77b59fe747 100644--- a/apps/desktop/src/renderer/__tests__/userMessageLinkify.test.ts+++ b/apps/desktop/src/renderer/__tests__/userMessageLinkify.test.ts@@ -88,6 +88,13 @@ describe('userMessageLinkify', () => {expect(urls('看 https://example.com/path这是说明')).toEqual(['https://example.com/path']);});+ it('keeps Unicode domain and path segments', () => {+ expect(urls('打开 https://example.com/路径 与 https://例子.测试/path')).toEqual([+ 'https://example.com/路径',+ 'https://例子.测试/path',+ ]);+ });+it('keeps apostrophes inside URL paths and at URL endings', () => {expect(urls("看 https://en.wikipedia.org/wiki/Guns_N'_Roses 然后")).toEqual(["https://en.wikipedia.org/wiki/Guns_N'_Roses",diff --git a/apps/mobile/src/__tests__/messageMarkdown.test.ts b/apps/mobile/src/__tests__/messageMarkdown.test.tsindex 737da3f8c5..22b6f52db9 100644--- a/apps/mobile/src/__tests__/messageMarkdown.test.ts+++ b/apps/mobile/src/__tests__/messageMarkdown.test.ts@@ -287,6 +287,12 @@ describe('messageMarkdown', () => {{ type: 'link', text: 'https://example.com/path', url: 'https://example.com/path' },{ type: 'text', text: ') 收尾' },]);+ expect(parseMobileMarkdownInlines('打开 https://example.com/路径 与 https://例子.测试/path')).toEqual([+ { type: 'text', text: '打开 ' },+ { type: 'link', text: 'https://example.com/路径', url: 'https://example.com/路径' },+ { type: 'text', text: ' 与 ' },+ { type: 'link', text: 'https://例子.测试/path', url: 'https://例子.测试/path' },+ ]);});it('parses common inline formatting tokens', () => {diff --git a/packages/maker-shared/src/__tests__/urlTextBoundary.test.ts b/packages/maker-shared/src/__tests__/urlTextBoundary.test.tsindex c8cfc2b257..e41f8bc427 100644--- a/packages/maker-shared/src/__tests__/urlTextBoundary.test.ts+++ b/packages/maker-shared/src/__tests__/urlTextBoundary.test.ts@@ -44,10 +44,33 @@ describe('clipBareHttpAutolinkText', () => {'https://example.com/path',);});++ it('keeps Unicode domain and path, but still cuts glued CJK prose', () => {+ expect(clipBareHttpAutolinkText('https://example.com/路径')).toBe(+ 'https://example.com/路径',+ );+ expect(clipBareHttpAutolinkText('https://例子.测试/path')).toBe(+ 'https://例子.测试/path',+ );+ expect(clipBareHttpAutolinkText('https://example.com/中文')).toBe(+ 'https://example.com/中文',+ );+ expect(clipBareHttpAutolinkText('https://example.com/path这是说明')).toBe(+ 'https://example.com/path',+ );+ expect(clipBareHttpAutolinkText('https://x.com/foo.说明')).toBe(+ 'https://x.com/foo',+ );+ expect(+ clipBareHttpAutolinkText('https://github.com/makecindy/cindy/pull/90_~说明', {+ stripMarkdownFormattingPunct: 'auto',+ }),+ ).toBe('https://github.com/makecindy/cindy/pull/90');+ });});describe('BARE_HTTP_URL_RE_SOURCE', () => {- it('stops the match before non-ASCII prose', () => {+ it('stops the match before fullwidth / CJK punctuation, not before letters', () => {expect(matchBareHttp('诊断已写在 https://github.com/example/app/issues/3561#issuecomment-5391602790(无 @)。',@@ -56,6 +79,12 @@ describe('BARE_HTTP_URL_RE_SOURCE', () => {expect(matchBareHttp('看 https://example.com/path。然后')).toBe('https://example.com/path',);+ expect(matchBareHttp('打开 https://example.com/路径 看')).toBe(+ 'https://example.com/路径',+ );+ expect(matchBareHttp('打开 https://例子.测试/path 看')).toBe(+ 'https://例子.测试/path',+ );});it('includes balanced ASCII parentheses for later clip', () => {diff --git a/packages/maker-shared/src/urlTextBoundary.ts b/packages/maker-shared/src/urlTextBoundary.tsindex 0e872c1e25..dad67b5225 100644--- a/packages/maker-shared/src/urlTextBoundary.ts+++ b/packages/maker-shared/src/urlTextBoundary.ts@@ -341,30 +341,64 @@ export function shrinkAutolinkTrailingJunk(}/**- * 扫描器用的裸 http(s) 源。空白 / 尖括号 / ASCII 引号 / 任何非 ASCII- * (含全角括号与中文)处结束,避免匹配阶段就把说明吃进候选。+ * 扫描器用的裸 http(s) 源。空白 / 尖括号 / ASCII 引号 / 弯引号 /+ * CJK 与全角标点处结束。汉字、假名、谚文可以出现在域名和路径里;* 半角括号留给 `clipBareHttpAutolink` 按配对/包裹处理。*/export const BARE_HTTP_URL_RE_SOURCE =- String.raw`https?://[^\s<>"\u0080-\uFFFF]+`;--const AUTOLINK_PROSE_BOUNDARY = new RegExp(- '[' +- '"`' +- '\\u2018-\\u201F' +- '\\u2026' +- '\\u3000-\\u303F' +- '\\u3040-\\u30FF' +- '\\u3400-\\u4DBF' +- '\\u4E00-\\u9FFF' +- '\\uAC00-\\uD7AF' +- '\\uFF00-\\uFFEF' +- ']',-);+ 'https?://[^ \t\r\n<>"\u2018-\u201F\u2026\u3000-\u303F\uFF00-\uFFEF]+';const MARKDOWN_FORMATTING_STRIP_BOUNDARY =/[\u3000-\u303F\u3040-\u30FF\u3400-\u4DBF\u4E00-\u9FFF\uAC00-\uD7AF\uFF00-\uFFEF]/;+function isAutolinkPunctuationBoundary(ch: string): boolean {+ const code = ch.codePointAt(0);+ if (code == null) return false;+ if (ch === '"' || ch === '`') return true;+ if (code >= 0x2018 && code <= 0x201f) return true;+ if (code === 0x2026) return true;+ if (code >= 0x3000 && code <= 0x303f) return true;+ if (code >= 0xff00 && code <= 0xffef) return true;+ return false;+}++function isUrlLetterScript(ch: string): boolean {+ const code = ch.codePointAt(0);+ if (code == null) return false;+ if (code >= 0x3040 && code <= 0x30ff) return true;+ if (code >= 0x3400 && code <= 0x4dbf) return true;+ if (code >= 0x4e00 && code <= 0x9fff) return true;+ if (code >= 0xac00 && code <= 0xd7af) return true;+ return false;+}++/**+ * 标点/全角符号永远是正文边界。+ * 汉字假名谚文:跟在 URL 结构符后面算地址(`/路径`、`例子.测试`),+ * 紧贴 ASCII 字母数字则是粘上去的说明(`path这是说明`)。+ */+function isAsciiTrailPunct(ch: string | undefined): boolean {+ return ch != null && ".,;:?!_~'*" .includes(ch);+}++function isGluedCjkProse(raw: string, index: number): boolean {+ let cursor = index - 1;+ while (cursor >= 0 && isAsciiTrailPunct(raw[cursor])) cursor -= 1;+ return cursor >= 0 && isAsciiAlnum(raw[cursor]);+}++function findAutolinkProseBoundary(raw: string): number {+ for (let index = 0; index < raw.length; ) {+ const code = raw.codePointAt(index);+ if (code == null) break;+ const char = String.fromCodePoint(code);+ if (isAutolinkPunctuationBoundary(char)) return index;+ if (isUrlLetterScript(char) && isGluedCjkProse(raw, index)) return index;+ index += char.length;+ }+ return raw.length;+}+export function markdownWrapMarkerFromPrefix(prefix: string | null | undefined): string | null {if (!prefix) return null;for (const marker of MARKDOWN_WRAP_MARKERS) {@@ -396,8 +430,8 @@ export function clipBareHttpAutolink(options.markdownWrapMarker === undefined? markdownWrapMarkerFromPrefix(prefix): options.markdownWrapMarker;- const boundaryIndex = raw.search(AUTOLINK_PROSE_BOUNDARY);- const boundaryCut = boundaryIndex >= 0 ? boundaryIndex : raw.length;+ const boundaryIndex = findAutolinkProseBoundary(raw);+ const boundaryCut = boundaryIndex;const markdownCut = cutBeforeClosingMarkdownWrap(raw, marker);const limited = Math.min(boundaryCut, markdownCut);const proseCut = Math.min(@@ -410,7 +444,7 @@ export function clipBareHttpAutolink((options.stripMarkdownFormattingPunct === 'auto' &&(markdownCut < raw.length ||hasTrailingMultiCharMarkdownMarkerAfterCodeHostResource(raw, proseCut) ||- (boundaryIndex >= 0 &&+ (boundaryIndex < raw.length &&proseCut === boundaryCut &&MARKDOWN_FORMATTING_STRIP_BOUNDARY.test(raw[boundaryIndex]))));return shrinkAutolinkTrailingJunk(raw, proseCut, {