Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix: address review — cut sentence stop after a complete host

Chrise03b68b69c12
diff --git a/apps/mobile/src/__tests__/messageMarkdown.test.ts b/apps/mobile/src/__tests__/messageMarkdown.test.ts
index b1b285699f..82c953856e 100644
--- a/apps/mobile/src/__tests__/messageMarkdown.test.ts
+++ b/apps/mobile/src/__tests__/messageMarkdown.test.ts
@@ -318,6 +318,16 @@ describe('messageMarkdown', () => {
},
{ type: 'text', text: ' 看' },
]);
+ expect(parseMobileMarkdownInlines('看 https://例子。测试。这是说明')).toEqual([
+ { type: 'text', text: '看 ' },
+ { type: 'link', text: 'https://例子。测试', url: 'https://例子。测试' },
+ { type: 'text', text: '。这是说明' },
+ ]);
+ expect(parseMobileMarkdownInlines('看 https://example.com。这是说明')).toEqual([
+ { type: 'text', text: '看 ' },
+ { type: 'link', text: 'https://example.com', url: 'https://example.com' },
+ { type: 'text', text: '。这是说明' },
+ ]);
expect(parseMobileMarkdownInlines('打开 https://子域。四字域名。测试 看')).toEqual([
{ type: 'text', text: '打开 ' },
{
diff --git a/packages/maker-shared/src/__tests__/urlTextBoundary.test.ts b/packages/maker-shared/src/__tests__/urlTextBoundary.test.ts
index f806915f39..00e49e9ec6 100644
--- a/packages/maker-shared/src/__tests__/urlTextBoundary.test.ts
+++ b/packages/maker-shared/src/__tests__/urlTextBoundary.test.ts
@@ -109,6 +109,12 @@ describe('clipBareHttpAutolinkText', () => {
expect(clipBareHttpAutolinkText('https://子域。四字域名。测试')).toBe(
'https://子域。四字域名。测试',
);
+ expect(clipBareHttpAutolinkText('https://例子。测试。这是说明')).toBe(
+ 'https://例子。测试',
+ );
+ expect(clipBareHttpAutolinkText('https://example.com。这是说明')).toBe(
+ 'https://example.com',
+ );
expect(clipBareHttpAutolinkText('https://example.com/path・说明')).toBe(
'https://example.com/path',
);
diff --git a/packages/maker-shared/src/urlTextBoundary.ts b/packages/maker-shared/src/urlTextBoundary.ts
index 5086497cb7..a0b31c3b81 100644
--- a/packages/maker-shared/src/urlTextBoundary.ts
+++ b/packages/maker-shared/src/urlTextBoundary.ts
@@ -361,8 +361,8 @@ function isAutolinkPunctuationBoundary(ch: string): boolean {
}
/** URL 标准会把这三者归一成 `.` 的域名分隔符。 */
-function isIdnDomainDot(ch: string): boolean {
- const code = ch.codePointAt(0);
+function isIdnDomainDot(ch: string | undefined): boolean {
+ const code = ch?.codePointAt(0);
return code === 0x3002 || code === 0xff0e || code === 0xff61;
}
@@ -397,23 +397,46 @@ function isHostLabelChar(ch: string | undefined): boolean {
return !isAutolinkPunctuationBoundary(ch);
}
+function isCjkLetter(ch: string): boolean {
+ return /[\u3040-\u30FF\u3400-\u4DBF\u4E00-\u9FFF\uAC00-\uD7AF\uF900-\uFAFF]/u.test(ch);
+}
+
+function nextHostLabelEnd(raw: string, from: number, hostEnd: number): number {
+ let index = from;
+ while (index < hostEnd) {
+ const code = raw.codePointAt(index);
+ if (code == null) break;
+ const char = String.fromCodePoint(code);
+ if (isIdnDomainDot(char) || char === '.') break;
+ if (!isHostLabelChar(char)) break;
+ index += char.length;
+ }
+ return index;
+}
+
function isIdnDotInHostname(
raw: string,
index: number,
hostStart: number,
hostEnd: number,
): boolean {
- return (
- index >= hostStart &&
- index < hostEnd &&
- isIdnDomainDot(raw[index] ?? '') &&
- isHostLabelChar(raw[index + 1])
- );
+ if (index < hostStart || index >= hostEnd) return false;
+ if (!isIdnDomainDot(raw[index] ?? '') || !isHostLabelChar(raw[index + 1])) return false;
+ const labelEnd = nextHostLabelEnd(raw, index + 1, hostEnd);
+ const chars = [...raw.slice(index + 1, labelEnd)];
+ if (chars.length === 0) return false;
+ // 俄文/拉丁等字母脚本是真 IDN 标签,不限长度。
+ if (chars.some((ch) => /^\p{L}$/u.test(ch) && !isCjkLetter(ch))) return true;
+ if (chars.some((ch) => /[A-Za-z0-9]/.test(ch))) return true;
+ // 纯汉字标签:后面还有域名分隔符说明主机还没完(`四字域名。测试`);
+ // 否则只留 1–3 字的 TLD 形标签,避免 `。这是说明` 并进主机名。
+ const after = raw[labelEnd];
+ if (after === '.' || isIdnDomainDot(after)) return true;
+ return chars.length <= 3;
}
/**
- * 标点/全角符号是正文边界。hostname 里后面还跟标签的 IDN 点号一律留下
- * (`пример。онлайн`、`子域。四字域名。测试`)。句末单独的 `。` 仍切掉。
+ * 标点是正文边界。hostname 里真 IDN 点号留下;完整主机后的 `。这是说明` 切掉。
*/
function findAutolinkProseBoundary(raw: string): number {
const { start: hostStart, end: hostEnd } = hostnameRange(raw);