The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 14:45 UTC
fix(web): bare URLs no longer swallow Arabic commas and question marks (#36779)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
nasser committed
Nov 14, 2026 at 17:53 UTC
e3305931412d82f8cf09474b23c7e5409ee360b7
2 files changed
+32
-23
packages/shared/src/markdownPipeline.test.ts
+9
-1
@@ -139,6 +139,14 @@ it.each([
139
["[記事](https://example.com/a,b)", "[記事](https://example.com/a,b)"],
140
["[http://example.com/a,b](http://example.com/a,b)", link("http://example.com/a,b")],
141
["`https://example.com/a。次`", "`https://example.com/a。次`"],
142
+ [
143
+ "منشور على https://example.com/report، ونسخته",
144
+ `منشور على ${link("https://example.com/report")}، ونسخته`,
145
+ ],
146
+ [
147
+ "هل يعمل **http://localhost:3000**؟ نعم؛ www.example.com۔",
148
+ `هل يعمل **${link("http://localhost:3000")}**؟ نعم؛ ${link("www.example.com")}۔`,
149
+ ],
150
[
151
"https://x.com/a_ https://x.com/b_",
152
`${link("https://x.com/a_")} ${link("https://x.com/b_")}`,
@@ -169,7 +177,7 @@ it.each([
177
}
178
});
179
172
-it("ends bare URLs at CJK punctuation with source positions", () => {
180
+it("ends bare URLs at CJK and Arabic punctuation with source positions", () => {
181
const processor = unified().use(remarkParse).use(CHAT_MARKDOWN_REMARK_PLUGINS);
182
const parse = (markdown: string) => processor.runSync(processor.parse(markdown), markdown);
183
const at = (line: number, column: number, offset: number) => ({ line, column, offset });
packages/shared/src/markdownPipeline.ts
+23
-22
@@ -246,7 +246,7 @@ const CHAT_MARKDOWN_SANITIZE_SCHEMA = {
246
247
export const CHAT_MARKDOWN_REMARK_PLUGINS: PluggableList = [
248
remarkGfm,
249
- remarkEndAutolinksAtCjkPunctuation,
249
+ remarkEndAutolinksAtScriptPunctuation,
250
remarkKeepAutolinkSuffixes,
251
remarkLinkAbsoluteFilePaths,
252
remarkKeepWindowsPaths,
@@ -261,7 +261,7 @@ export const CHAT_MARKDOWN_REMARK_PLUGINS: PluggableList = [
261
262
export const CHAT_MARKDOWN_REMARK_PLUGINS_WITH_BREAKS: PluggableList = [
263
remarkGfm,
264
- remarkEndAutolinksAtCjkPunctuation,
264
+ remarkEndAutolinksAtScriptPunctuation,
265
remarkKeepAutolinkSuffixes,
266
remarkLinkAbsoluteFilePaths,
267
remarkKeepWindowsPaths,
@@ -471,20 +471,21 @@ function remarkKeepAutolinkSuffixes(): Transformer<Root> {
471
};
472
}
473
474
-// Punctuation and symbols from CJK Symbols and Punctuation and from Halfwidth and Fullwidth Forms.
475
-const CJK_PUNCTUATION = /(?=[ -〿-])[\p{P}\p{S}]/u;
474
+// Punctuation and symbols from CJK Symbols and Punctuation and from Halfwidth and Fullwidth Forms,
475
+// plus the Arabic-script comma, semicolon, question mark, and full stop.
476
+const SCRIPT_PUNCTUATION = /(?=[ -〿-،؛؟۔])[\p{P}\p{S}]/u;
477
478
/**
478
- * GFM runs a bare URL on until whitespace, so Chinese and Japanese punctuation joins it, along with
479
- * the rest of the sentence and any `**` that should have closed around it. A URL that is ASCII up to
480
- * such a mark ends there. Unicode earlier in the URL means the mark may belong to it, so it stays.
479
+ * GFM runs a bare URL on until whitespace, so Chinese, Japanese, and Arabic punctuation joins it,
480
+ * along with the rest of the sentence and any `**` that should have closed around it. A URL that is
481
+ * ASCII up to such a mark ends there. Unicode earlier in the URL means the mark may belong to it, so it stays.
482
*/
482
-function cjkPunctuationIndex(link: Link): number {
483
+function scriptPunctuationIndex(link: Link): number {
484
const label = link.children.length === 1 ? link.children[0] : undefined;
485
if (label?.type !== "text" || !/^https?:\/\//i.test(link.url)) return -1;
486
if (link.url !== label.value && link.url !== `http://${label.value}`) return -1;
487
const index = label.value.search(/[^!-~]/u);
487
- return index > 0 && CJK_PUNCTUATION.test(label.value.charAt(index)) ? index : -1;
488
+ return index > 0 && SCRIPT_PUNCTUATION.test(label.value.charAt(index)) ? index : -1;
489
}
490
491
/** GFM's text pass links bare URLs without positions; its tokenizer's links span their URL. */
@@ -502,14 +503,14 @@ function isBareLink(link: Link, source: string): boolean {
503
}
504
505
/** Source offsets of the marks that tokenized bare URLs run past. */
505
-function cjkPunctuationOffsets(node: RootContent, source: string): number[] {
506
+function scriptPunctuationOffsets(node: RootContent, source: string): number[] {
507
if (node.type === "link") {
507
- const index = cjkPunctuationIndex(node);
508
+ const index = scriptPunctuationIndex(node);
509
const start = node.position?.start.offset;
510
return index > 0 && start !== undefined && isBareLink(node, source) ? [start + index] : [];
511
}
512
return "children" in node && node.type !== "linkReference"
512
- ? (node.children as RootContent[]).flatMap((child) => cjkPunctuationOffsets(child, source))
513
+ ? (node.children as RootContent[]).flatMap((child) => scriptPunctuationOffsets(child, source))
514
: [];
515
}
516
@@ -537,7 +538,7 @@ function countBelow(sorted: readonly number[], value: number): number {
538
* dropped and positions mapped back to the source. Returns false and leaves the block alone when its
539
* text would parse differently on its own, as a quote's continuation lines do.
540
*/
540
-function reparseAtCjkPunctuation(
541
+function reparseAtScriptPunctuation(
542
processor: Processor,
543
block: Paragraph | Heading | TableCell,
544
source: string,
@@ -570,7 +571,7 @@ function reparseAtCjkPunctuation(
571
.join("\t");
572
const [paragraph, ...rest] = (processor.parse(marked) as Root).children;
573
if (paragraph?.type !== "paragraph" || rest.length > 0) return false;
573
- const more = cjkPunctuationOffsets(paragraph, marked);
574
+ const more = scriptPunctuationOffsets(paragraph, marked);
575
if (more.length > 0) {
576
marks.push(...more.map(unmarked));
577
continue;
@@ -613,16 +614,16 @@ function reparseAtCjkPunctuation(
614
}
615
616
/** Ends the bare URLs a reparse could not, and those GFM's text pass linked after emphasis. */
616
-function splitAtCjkPunctuation(node: RootContent, source: string) {
617
+function splitAtScriptPunctuation(node: RootContent, source: string) {
618
if (!("children" in node) || node.type === "link" || node.type === "linkReference") return;
619
const children = node.children as RootContent[];
620
for (let index = 0; index < children.length; index++) {
621
const child = children[index]!;
622
if (child.type !== "link") {
622
- splitAtCjkPunctuation(child, source);
623
+ splitAtScriptPunctuation(child, source);
624
continue;
625
}
625
- const at = isBareLink(child, source) ? cjkPunctuationIndex(child) : -1;
626
+ const at = isBareLink(child, source) ? scriptPunctuationIndex(child) : -1;
627
const label = child.children[0];
628
if (at < 0 || label?.type !== "text") continue;
629
// GFM drops this punctuation from the end of a URL; remarkKeepAutolinkSuffixes restores `_` and `~`.
@@ -646,15 +647,15 @@ function splitAtCjkPunctuation(node: RootContent, source: string) {
647
}
648
}
649
649
-function remarkEndAutolinksAtCjkPunctuation(this: Processor): Transformer<Root> {
650
+function remarkEndAutolinksAtScriptPunctuation(this: Processor): Transformer<Root> {
651
return (tree, file) => {
652
const source = String(file);
652
- if (!CJK_PUNCTUATION.test(source)) return;
653
+ if (!SCRIPT_PUNCTUATION.test(source)) return;
654
const visit = (node: RootContent) => {
655
if (node.type === "paragraph" || node.type === "heading" || node.type === "tableCell") {
655
- const offsets = cjkPunctuationOffsets(node, source);
656
- if (offsets.length > 0) reparseAtCjkPunctuation(this, node, source, offsets);
657
- splitAtCjkPunctuation(node, source);
656
+ const offsets = scriptPunctuationOffsets(node, source);
657
+ if (offsets.length > 0) reparseAtScriptPunctuation(this, node, source, offsets);
658
+ splitAtScriptPunctuation(node, source);
659
} else if ("children" in node) {
660
(node.children as RootContent[]).forEach(visit);
661
}