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, 09:45 UTC
fix(shared): inline code paths with spaces become file chips (#37750)
Julius Marminge committed
Nov 16, 2026 at 12:20 UTC
6f5861fa27c9d1c21e5b48677ac0da1188bfd233
4 files changed
+60
-6
apps/mobile/src/lib/markdownDocument.ts
+13
-3
@@ -3,7 +3,11 @@ import { unified, type Processor } from "unified";
3
import remarkParse from "remark-parse";
4
import remarkGfm from "remark-gfm";
5
import { remarkKeepWindowsProsePaths } from "@t3tools/shared/markdownWindowsPaths";
6
-import { absoluteFilePathMatches, parseMarkdownFileLink } from "@t3tools/shared/markdownLinks";
6
+import {
7
+ absoluteFilePathMatches,
8
+ inlineCodeFilePathCandidate,
9
+ parseMarkdownFileLink,
10
+} from "@t3tools/shared/markdownLinks";
11
import { isWindowsAbsolutePath } from "@t3tools/shared/path";
12
13
const parser = unified().use(remarkParse).use(remarkGfm).use(remarkKeepWindowsProsePaths);
@@ -322,6 +326,11 @@ export function withReferenceDefinitions(
326
// Start only at the beginning of a backtick run to avoid retrying every suffix.
327
const INLINE_CODE_SPAN = /(?<!`)`+([^`\r\n]+)`+/g;
328
329
+// The native regex stops at whitespace; the shared classifier decides paths with spaces.
330
+function isInlineCodeFileLink(code: string, fileLink: RegExp): boolean {
331
+ return fileLink.test(code) || (/\s/.test(code) && inlineCodeFilePathCandidate(code) !== null);
332
+}
333
+
334
export function markdownWithInlineFileLinks(markdown: string, fileLink: RegExp): string {
335
return transformNativeMarkdown(markdown, fileLink, false);
336
}
@@ -335,7 +344,7 @@ function transformNativeMarkdown(
344
let linkFiles = false;
345
if (fileLink) {
346
for (const [, code] of markdown.matchAll(INLINE_CODE_SPAN)) {
338
- if (fileLink.test(code!.trim())) {
347
+ if (isInlineCodeFileLink(code!.trim(), fileLink)) {
348
linkFiles = true;
349
break;
350
}
@@ -354,7 +363,8 @@ function transformNativeMarkdown(
363
if (
364
start !== undefined &&
365
end !== undefined &&
357
- fileLink?.test(node.value) &&
366
+ fileLink !== undefined &&
367
+ isInlineCodeFileLink(node.value, fileLink) &&
368
parseMarkdownFileLink(node.value) !== null &&
369
!/[<>]/.test(node.value)
370
) {
apps/mobile/src/lib/markdownInlineFileLinks.test.ts
+4
-1
@@ -99,13 +99,16 @@ describe("inline code that names a file", () => {
99
"數學.ts:2",
100
"src/數學.ts:2-4",
101
"docker/Dockerfile",
102
+ "/Users/me/Path Test/notes with spaces.md",
103
+ "~/Library/Mobile Documents/notes.md",
104
]) {
105
expect(rewrite(`See \`${path}\`.`), path).toBe(`See [${path}](<${path}>).`);
106
}
107
});
108
109
it("keeps commands, identifiers and URLs as code", () => {
108
- const markdown = "Run `vp test run`, call `useMemo`, open `https://example.com/a.ts`.";
110
+ const markdown =
111
+ "Run `vp test run`, `/usr/bin/python3 -m venv .venv`, call `useMemo`, open `https://example.com/a.ts`.";
112
expect(rewrite(markdown)).toBe(markdown);
113
});
114
packages/shared/src/markdownLinks.test.ts
+15
@@ -48,6 +48,21 @@ describe("inlineCodeFilePathCandidate", () => {
48
["./bin/run:12", "./bin/run:12"],
49
["src/資料.備份:12", "src/資料.備份:12"],
50
["src/foo.c++:12", "src/foo.c++:12"],
51
+ // regression: #37740 absolute paths with spaces are files, commands are not
52
+ ["/Users/me/Path Test/notes with spaces.md", "/Users/me/Path Test/notes with spaces.md"],
53
+ ["~/Library/Mobile Documents/notes.md", "~/Library/Mobile Documents/notes.md"],
54
+ [
55
+ "/Users/me/Library/CloudStorage/OneDrive-Org/Alex/Partners/Acme/Finance Use Cases/working/2026-11-16 message - draft.md",
56
+ "/Users/me/Library/CloudStorage/OneDrive-Org/Alex/Partners/Acme/Finance Use Cases/working/2026-11-16 message - draft.md",
57
+ ],
58
+ ["cd /tmp && ls", null],
59
+ ["/usr/bin/python3 -m venv .venv", null],
60
+ ["/usr/local/bin/node server.js", null],
61
+ ["/usr/bin/env python3 foo.py", null],
62
+ ["/opt/homebrew/bin/python3 manage.py", null],
63
+ ["/bin/echo hello world.txt", null],
64
+ ["~/bin/run tests.sh", null],
65
+ ["/Users/me/notes with spaces.md", "/Users/me/notes with spaces.md"],
66
])("distinguishes file paths from code and hostnames in %s", (source, candidate) => {
67
expect(inlineCodeFilePathCandidate(source)).toBe(candidate);
68
});
packages/shared/src/markdownLinks.ts
+28
-2
@@ -30,7 +30,30 @@ const POSITION_SUFFIX_PATTERN = /:\d+(?::\d+|-\d+)?$/;
30
31
const POSITION_ONLY_PATTERN = /^\d+(?::\d+|-\d+)?$/;
32
33
-const INLINE_CODE_DISQUALIFIER_PATTERN = /[\s`]/;
33
+const INLINE_CODE_WHITESPACE_PATTERN = /\s/;
34
+
35
+// Inline code with spaces is a file only when it is absolute and every word is a plain name:
36
+// `/Users/me/Mobile Documents/a - b.md` is, `/usr/bin/python3 -m venv .venv` (a flag) is not.
37
+// A space only in the last segment reads as a command (`/usr/local/bin/node server.js`), so it
38
+// must sit under a user root, and nothing after a bin folder counts.
39
+const SPACED_ABSOLUTE_PATH_ROOT_PATTERN = /^(?:\/|~\/|[A-Za-z]:[\\/])/;
40
+const SPACED_PATH_BODY_PATTERN =
41
+ /^(?:[\p{L}\p{M}\p{N}._$+@()[\]-]+(?: (?!-+\p{L})[\p{L}\p{M}\p{N}._$+@()[\]-]+)*(?:[\\/]|$))+$/u;
42
+
43
+function isSpacedAbsoluteFilePath(text: string): boolean {
44
+ const root = SPACED_ABSOLUTE_PATH_ROOT_PATTERN.exec(text)?.[0];
45
+ if (root === undefined) return false;
46
+ const body = text.slice(root.length).replace(POSITION_SUFFIX_PATTERN, "");
47
+ if (!SPACED_PATH_BODY_PATTERN.test(body)) return false;
48
+ const firstSpace = body.indexOf(" ");
49
+ const foldersBeforeSpace = body.slice(0, firstSpace).split(PATH_SEPARATOR_PATTERN).slice(0, -1);
50
+ if (foldersBeforeSpace.some((folder) => folder === "bin" || folder === "sbin")) return false;
51
+ const spaceInFolder = PATH_SEPARATOR_PATTERN.test(body.slice(firstSpace));
52
+ if (!spaceInFolder && root === "/" && !/^(?:Users|home)[\\/]/.test(body)) return false;
53
+ if (PATH_SEPARATOR_PATTERN.test(body.at(-1) ?? "")) return true;
54
+ const basename = body.split(PATH_SEPARATOR_PATTERN).at(-1) ?? "";
55
+ return FILE_EXTENSION_PATTERN.test(basename) || EXTENSIONLESS_FILE_NAMES.has(basename);
56
+}
57
58
const PATH_SEPARATOR_PATTERN = /[\\/]/;
59
// Agents shorten long paths with a `...` or `…` segment, which no file chip can open.
@@ -177,7 +200,10 @@ function looksLikeHostname(segment: string, hasPosition: boolean): boolean {
200
201
export function inlineCodeFilePathCandidate(codeText: string): string | null {
202
const trimmed = codeText.trim();
180
- if (trimmed.length === 0 || INLINE_CODE_DISQUALIFIER_PATTERN.test(trimmed)) return null;
203
+ if (trimmed.length === 0 || trimmed.includes("`")) return null;
204
+ if (INLINE_CODE_WHITESPACE_PATTERN.test(trimmed) && !isSpacedAbsoluteFilePath(trimmed)) {
205
+ return null;
206
+ }
207
208
const candidate = isWindowsAbsolutePath(trimmed) ? trimmed : trimmed.replaceAll("\\", "/");
209
const hasPosition = POSITION_SUFFIX_PATTERN.test(candidate);