@devries-cameron20 / t3code Mirror · read-only / commits / bb646d2cad
Fork 0

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, 21:00 UTC

fix(shared): links to bracketed filenames keep their folder labels (#34759)

Julius Marminge committed Nov 11, 2026 at 21:28 UTC bb646d2caded23e0942e67b75fd85e1e5e798cea
2 files changed +14 -1
packages/shared/src/markdownLinks.test.ts
+1
@@ -158,6 +158,7 @@ describe("extractMarkdownLinkHrefs", () => {
158 ["[".repeat(32_000), []],
159 ["[a](<foo)bar> invalid [b](ok)", ["<foo", "ok"]],
160 ["[[[nested](src/main.ts) [unfinished", ["src/main.ts"]],
161 + [`See ${serializeComposerFileLink("pages/posts/[id].tsx")} now`, ["pages/posts/%5Bid%5D.tsx"]],
162 ])("extracts links from incomplete and nested text", (markdown, hrefs) => {
163 expect(extractMarkdownLinkHrefs(markdown)).toEqual(hrefs);
164 });
packages/shared/src/markdownLinks.ts
+13 -1
@@ -407,6 +407,18 @@ function markdownLinkDestinationScanner(markdown: string) {
407 };
408 }
409
410 +// The composer escapes brackets in labels (`[\[id\].tsx](...)`), and `\]` does not close one.
411 +function unescapedLabelEnd(markdown: string, start: number): number {
412 + let end = markdown.indexOf("]", start);
413 + while (end !== -1) {
414 + let backslashes = 0;
415 + while (end - backslashes > start && markdown[end - backslashes - 1] === "\\") backslashes += 1;
416 + if (backslashes % 2 === 0) return end;
417 + end = markdown.indexOf("]", end + 1);
418 + }
419 + return -1;
420 +}
421 +
422 export function extractMarkdownLinkHrefs(markdown: string): string[] {
423 const hrefs: string[] = [];
424 const scanDestination = markdownLinkDestinationScanner(markdown);
@@ -414,7 +426,7 @@ export function extractMarkdownLinkHrefs(markdown: string): string[] {
426 while (cursor < markdown.length) {
427 const labelStart = markdown.indexOf("[", cursor);
428 if (labelStart === -1) break;
417 - const labelEnd = markdown.indexOf("]", labelStart + 1);
429 + const labelEnd = unescapedLabelEnd(markdown, labelStart + 1);
430 if (labelEnd === -1) break;
431
432 // Skip a failed label once; nested openings share its closing bracket.