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, 19:30 UTC
fix(web): ../ file links outside the workspace open as host files (#22853)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Theo Browne committed
Oct 21, 2026 at 15:12 UTC
edce5f0e53e8f0a80ed0c6b553edfe7b6467bc14
2 files changed
+13
-1
packages/shared/src/path.test.ts
+4
@@ -43,6 +43,10 @@ describe("workspaceRelativeFilePath", () => {
43
["/Repo/Project/src/main.ts", "/repo/project", null],
44
["C:/USERS/mike/t3code/main.ts", "c:/users/MIKE/t3code", "main.ts"],
45
["/repo/project-two/a.ts", "/repo/project", null],
46
+ // regression: #16354 a `..` that leaves the root is a host path, not a workspace path
47
+ ["/repo/project/../other/notes.md", "/repo/project", null],
48
+ ["C:\\repo\\project\\src\\..\\..\\notes.md", "C:\\repo\\project", null],
49
+ ["/repo/project/docs/a/../b.md", "/repo/project", "docs/a/../b.md"],
50
])("relates %s to %s", (path, workspaceRoot, relativePath) => {
51
expect(workspaceRelativeFilePath(path, workspaceRoot)).toBe(relativePath);
52
});
packages/shared/src/path.ts
+9
-1
@@ -98,7 +98,15 @@ export function workspaceRelativeFilePath(
98
const rootForCompare = caseInsensitive ? normalizedRoot.toLowerCase() : normalizedRoot;
99
if (pathForCompare.replace(/\/+$/, "") === rootForCompare) return ".";
100
if (!pathForCompare.startsWith(`${rootForCompare}/`)) return null;
101
- return normalizedPath.slice(normalizedRoot.length + 1);
101
+ const relativePath = normalizedPath.slice(normalizedRoot.length + 1);
102
+ // `/repo/../x` starts with the root but escapes it; the server rejects that as a workspace path.
103
+ let depth = 0;
104
+ for (const segment of relativePath.split("/")) {
105
+ if (segment === "..") depth -= 1;
106
+ else if (segment.length > 0 && segment !== ".") depth += 1;
107
+ if (depth < 0) return null;
108
+ }
109
+ return relativePath;
110
}
111
112
export function isAbsolutePath(value: string): boolean {