@devries-cameron20 / t3code Mirror · read-only / commits / 65efae1adb
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 22, 05:45 UTC

fix(shared): relative file links with routing punctuation open as files (#28637)

Abhishek B R committed Nov 4, 2026 at 04:35 UTC 65efae1adb7f2e326bc828b6fd8538343c5b9186
2 files changed +35 -11
packages/shared/src/markdownLinks.test.ts
+29 -6
@@ -1,5 +1,6 @@
1 import { workspaceRelativeFilePath } from "./path.ts";
2 import { describe, expect, it } from "vite-plus/test";
3 +import { serializeComposerFileLink } from "./composerTrigger.ts";
4 import { extractMarkdownLinkHrefs, resolveMarkdownFileLinkTarget } from "./markdownLinks.ts";
5
6 import {
@@ -38,16 +39,38 @@ describe("parseMarkdownFileLink", () => {
39 ["C:%5Crepo%5Cimage.png", "C:\\repo\\image.png"],
40 ["</D:/Programme/t3code/ChatMarkdown.tsx:1>", "D:/Programme/t3code/ChatMarkdown.tsx"],
41 ["file://localhost/home/me/notes.md", "/home/me/notes.md"],
42 + ["app/routes/posts.$postId.tsx", "app/routes/posts.$postId.tsx"],
43 + ["src/routes/+page.svelte", "src/routes/+page.svelte"],
44 + ["app/(marketing)/page.tsx:12", "app/(marketing)/page.tsx"],
45 + ["pages/posts/%5Bid%5D.tsx", "pages/posts/[id].tsx"],
46 + ["+page.svelte", "+page.svelte"],
47 + ["[id].tsx", "[id].tsx"],
48 ])("recognizes %s as a file", (href, path) => {
49 expect(parseMarkdownFileLink(href)?.path).toBe(path);
50 });
51
45 - it.each(["https://example.com/docs", "/chat/settings#L3", "TODO:12", "patches"])(
46 - "does not treat %s as a file",
47 - (href) => {
48 - expect(parseMarkdownFileLink(href)).toBeNull();
49 - },
50 - );
52 + it.each([
53 + "app/routes/posts.$postId.tsx",
54 + "pages/posts/[id].tsx",
55 + "docs/My File (draft).md",
56 + "@scope/package.json",
57 + "$postId.tsx",
58 + ])("reads back the composer's link to %s", (path) => {
59 + const destination = /\]\((.*)\)$/.exec(serializeComposerFileLink(path))?.[1];
60 + expect(parseMarkdownFileLink(destination ?? "")?.path).toBe(path);
61 + });
62 +
63 + it.each([
64 + "https://example.com/docs",
65 + "/chat/settings#L3",
66 + "TODO:12",
67 + "patches",
68 + "me@example.com",
69 + "foo(bar)",
70 + "$HOME",
71 + ])("does not treat %s as a file", (href) => {
72 + expect(parseMarkdownFileLink(href)).toBeNull();
73 + });
74
75 it("recognizes a relative folder that ends in a slash", () => {
76 expect(parseMarkdownFileLink("patches/")).toEqual({ path: "patches/" });
packages/shared/src/markdownLinks.ts
+6 -5
@@ -14,14 +14,15 @@ import {
14
15 const RELATIVE_PATH_PREFIX_PATTERN = /^(~\/|\.{1,2}\/)/;
16
17 -// Names may use any script (`線性代數/考試.pdf`). The final segment is optional so an
18 -// explicit folder link may end in `/` (`patches/`, `docs/My Folder/`). A bare name with no
19 -// slash still fails.
17 +// Names may use any script (`線性代數/考試.pdf`) and routing punctuation (`posts.$id.tsx`,
18 +// `(group)/[id]/+page.svelte`, `@scope/pkg`). The final segment is optional so an explicit
19 +// folder link may end in `/` (`patches/`, `docs/My Folder/`). A bare name with no slash still fails.
20 const RELATIVE_FILE_PATH_PATTERN =
21 - /^(?:[\p{L}\p{M}\p{N}._-]+(?: +[\p{L}\p{M}\p{N}._-]+)*\/)+(?:[\p{L}\p{M}\p{N}._-]+(?: +[\p{L}\p{M}\p{N}._-]+)*(?::\d+){0,2})?$/u;
21 + /^(?:[\p{L}\p{M}\p{N}._$+@()[\]-]+(?: +[\p{L}\p{M}\p{N}._$+@()[\]-]+)*\/)+(?:[\p{L}\p{M}\p{N}._$+@()[\]-]+(?: +[\p{L}\p{M}\p{N}._$+@()[\]-]+)*(?::\d+){0,2})?$/u;
22
23 +// No `@` here: `me@example.com` is an address, not a file.
24 const RELATIVE_FILE_NAME_PATTERN =
24 - /^[\p{L}\p{M}\p{N}._-]+(?: +[\p{L}\p{M}\p{N}._-]+)*\.[\p{L}\p{M}\p{N}_-]+(?::\d+){0,2}$/u;
25 + /^[\p{L}\p{M}\p{N}._$+()[\]-]+(?: +[\p{L}\p{M}\p{N}._$+()[\]-]+)*\.[\p{L}\p{M}\p{N}_-]+(?::\d+){0,2}$/u;
26
27 const EXTERNAL_SCHEME_PATTERN = /^([A-Za-z][A-Za-z0-9+.-]*):(.*)$/;
28