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 — IDN dots only inside the hostname
Chris78923dd8cf11
diff --git a/apps/desktop/src/renderer/__tests__/userMessageLinkify.test.ts b/apps/desktop/src/renderer/__tests__/userMessageLinkify.test.tsindex 8a3bf0f7d7..0235cf0bb7 100644--- a/apps/desktop/src/renderer/__tests__/userMessageLinkify.test.ts+++ b/apps/desktop/src/renderer/__tests__/userMessageLinkify.test.ts@@ -99,6 +99,9 @@ describe('userMessageLinkify', () => {expect(urls('打开 https://例子。测试/path')).toEqual(['https://例子。测试/path',]);+ expect(urls('看 http://localhost:3000。然后')).toEqual([+ 'http://localhost:3000',+ ]);expect(urls('打开 https://example.com/ABC 与 https://example.com/カタカナ')).toEqual(['https://example.com/ABC','https://example.com/カタカナ',diff --git a/apps/mobile/src/__tests__/messageMarkdown.test.ts b/apps/mobile/src/__tests__/messageMarkdown.test.tsindex e3edb8e99c..53ba083d76 100644--- a/apps/mobile/src/__tests__/messageMarkdown.test.ts+++ b/apps/mobile/src/__tests__/messageMarkdown.test.ts@@ -287,6 +287,11 @@ describe('messageMarkdown', () => {{ type: 'link', text: 'https://example.com/path', url: 'https://example.com/path' },{ type: 'text', text: ') 收尾' },]);+ expect(parseMobileMarkdownInlines('看 http://localhost:3000。然后')).toEqual([+ { type: 'text', text: '看 ' },+ { type: 'link', text: 'http://localhost:3000', url: 'http://localhost:3000' },+ { type: 'text', text: '。然后' },+ ]);expect(parseMobileMarkdownInlines('打开 https://例子。测试/path 看')).toEqual([{ type: 'text', text: '打开 ' },{ type: 'link', text: 'https://例子。测试/path', url: 'https://例子。测试/path' },diff --git a/packages/maker-shared/src/__tests__/urlTextBoundary.test.ts b/packages/maker-shared/src/__tests__/urlTextBoundary.test.tsindex f1c9bb3a22..c59fc5b049 100644--- a/packages/maker-shared/src/__tests__/urlTextBoundary.test.ts+++ b/packages/maker-shared/src/__tests__/urlTextBoundary.test.ts@@ -85,6 +85,15 @@ describe('clipBareHttpAutolinkText', () => {expect(clipBareHttpAutolinkText('https://example.com/path。然后')).toBe('https://example.com/path',);+ expect(clipBareHttpAutolinkText('http://localhost:3000。然后')).toBe(+ 'http://localhost:3000',+ );+ expect(clipBareHttpAutolinkText('https://[::1]:3000。然后')).toBe(+ 'https://[::1]:3000',+ );+ expect(clipBareHttpAutolinkText('https://例子。测试:443/path')).toBe(+ 'https://例子。测试:443/path',+ );});});diff --git a/packages/maker-shared/src/urlTextBoundary.ts b/packages/maker-shared/src/urlTextBoundary.tsindex 993ef86151..9f1eec9ba9 100644--- a/packages/maker-shared/src/urlTextBoundary.ts+++ b/packages/maker-shared/src/urlTextBoundary.ts@@ -371,29 +371,48 @@ function isIdnDomainDot(ch: string): boolean {return code === 0x3002 || code === 0xff0e || code === 0xff61;}-function authorityEndIndex(raw: string): number {- const scheme = raw.match(/^https?:\/\//i);- const start = scheme ? scheme[0].length : 0;- for (let index = start; index < raw.length; index += 1) {- const ch = raw[index];+function firstAuthDelimiterIndex(text: string, from = 0): number {+ for (let index = from; index < text.length; index += 1) {+ const ch = text[index];if (ch === '/' || ch === '?' || ch === '#') return index;}- return raw.length;+ return text.length;+}++/** IDN 点号只在 hostname 内保留;端口和 IPv6 `]` 之后仍是正文边界。 */+function hostnameEndIndex(raw: string): number {+ const scheme = raw.match(/^https?:\/\//i);+ let start = scheme ? scheme[0].length : 0;+ const authEnd = firstAuthDelimiterIndex(raw, start);+ const at = raw.lastIndexOf('@', authEnd - 1);+ if (at >= start) start = at + 1;+ if (raw[start] === '[') {+ const close = raw.indexOf(']', start + 1);+ return close >= 0 && close < authEnd ? close + 1 : authEnd;+ }+ for (let index = start; index < authEnd; index += 1) {+ if (raw[index] === ':') return index;+ }+ return authEnd;+}++function isIdnDotInHostname(raw: string, index: number, hostnameEnd: number): boolean {+ return index < hostnameEnd && isIdnDomainDot(raw[index] ?? '');}/**- * 标点/全角符号是正文边界;authority 里的 IDN 点号(`例子。测试`)留下。- * 路径开始后的 `。` 仍当句号切掉。无标点的 `path这是说明` 不猜。+ * 标点/全角符号是正文边界;hostname 里的 IDN 点号(`例子。测试`)留下。+ * 端口、IPv6 `]`、路径之后的 `。` 仍当句号切掉。*/function findAutolinkProseBoundary(raw: string): number {- const authorityEnd = authorityEndIndex(raw);+ const hostnameEnd = hostnameEndIndex(raw);for (let index = 0; index < raw.length; ) {const code = raw.codePointAt(index);if (code == null) break;const char = String.fromCodePoint(code);if (isAutolinkPunctuationBoundary(char) &&- !(index < authorityEnd && isIdnDomainDot(char))+ !isIdnDotInHostname(raw, index, hostnameEnd)) {return index;}