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, 13:30 UTC
fix(web): diff file Open and Reveal reach a file whose name has a backslash (#23167)
Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Victor committed
Nov 14, 2026 at 18:10 UTC
2b6c14bbf1c4883a436475cbf02ac0b3032598df
5 files changed
+106
-27
apps/web/src/components/DiffPanel.browser.test.tsx
+32
@@ -94,6 +94,7 @@ vi.mock("./DiffFilePathCopyButton", () => ({ DiffFilePathCopyButton: () => null
94
95
import DiffPanel from "./DiffPanel";
96
import { useDiffPanelSessionStore, useDiffPanelStore } from "~/diffPanelStore";
97
+import { selectThreadRightPanelState, useRightPanelStore } from "~/rightPanelStore";
98
99
const cwd = "/project-worktree";
100
const errorMessage = "Could not find a common commit between 'origin/orphan' and HEAD.";
@@ -126,6 +127,7 @@ function setup(failedBaseRef: string | null) {
127
branchBaseRefByThreadKey: {},
128
});
129
useDiffPanelSessionStore.setState({ collapsedFileKeysByScopeKey: {} });
130
+ useRightPanelStore.setState({ byThreadKey: {}, threadPanelVisibilityByThreadKey: {} });
131
};
132
reset();
133
state.diffFilesCollapsed = false;
@@ -233,6 +235,36 @@ it.each([
235
},
236
);
237
238
+it("opens a repository-relative file from a nested project without a remote", async () => {
239
+ using context = setup("origin/orphan");
240
+ state.thread = { ...state.thread!, worktreePath: null };
241
+ const path = "project/back\\slash.txt";
242
+ const metadata = preview();
243
+ const source = {
244
+ ...metadata.sources[0]!,
245
+ files: [{ path, previousPath: null, additions: 1, deletions: 0 }],
246
+ };
247
+ state.previews.set("main", Atom.make(AsyncResult.success({ ...metadata, sources: [source] })));
248
+ state.status = Atom.make(
249
+ AsyncResult.success({
250
+ ...AsyncResult.getOrElse(context.registry.get(state.status), () => {
251
+ throw new Error("Missing status");
252
+ }),
253
+ workingTree: { rootPath: "/", files: [], insertions: 0, deletions: 0 },
254
+ }),
255
+ );
256
+ useDiffPanelStore.getState().selectBranchBaseRef(context.threadRef, "main");
257
+ await using screen = await render(
258
+ <RegistryContext.Provider value={context.registry}>
259
+ <DiffPanel composerDraftTarget={context.threadRef} workspaceMutationId={null} visible />
260
+ </RegistryContext.Provider>,
261
+ );
262
+ await userEvent.click(screen.getByText(path, { exact: true }));
263
+ expect(
264
+ selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, context.threadRef),
265
+ ).toMatchObject({ activeSurfaceId: "file:back\\slash.txt" });
266
+});
267
+
268
it.each([false, true])(
269
"expands an unloaded file on the first click with default collapse %s",
270
async (collapsed) => {
apps/web/src/components/DiffPanel.tsx
+3
-3
@@ -254,9 +254,6 @@ export default function DiffPanel({
254
: null,
255
);
256
const activeCwd = activeThread?.worktreePath ?? activeProject?.workspaceRoot;
257
- const activeRepositoryRoot = activeThread?.worktreePath
258
- ? undefined
259
- : activeProject?.repositoryIdentity?.rootPath;
257
const serverConfig = useAtomValue(
258
serverEnvironment.configValueAtom(activeThread?.environmentId ?? null),
259
);
@@ -274,6 +271,9 @@ export default function DiffPanel({
271
})
272
: null,
273
);
274
+ const activeRepositoryRoot =
275
+ gitStatusQuery.data?.workingTree.rootPath ??
276
+ (activeThread?.worktreePath ? undefined : activeProject?.repositoryIdentity?.rootPath);
277
const diffSelection = useDiffPanelStore((state) =>
278
selectThreadDiffPanelSelection(state.byThreadKey, routeThreadRef),
279
);
apps/web/src/components/chat/TimelineAssistantRows.tsx
+17
-2
@@ -32,6 +32,11 @@ import { readThreadTurnItems } from "../../state/entities";
32
import { useV2ItemSupport } from "../../state/v2ItemSupport";
33
import { TimelineRowCtx, TimelineRowActivityCtx, type TimelineRow } from "./timelineRowContext";
34
import { MESSAGE_HEADING_LEVEL, MessageAuthorHeading } from "./TimelineRowParts";
35
+import { useAtomValue } from "@effect/atom-react";
36
+import { AsyncResult, Atom } from "effect/reactivity";
37
+import { vcsEnvironment } from "../../state/vcs";
38
+
39
+const NO_VCS_STATUS = Atom.make(AsyncResult.initial());
40
41
export function AssistantTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message" }> }) {
42
const ctx = use(TimelineRowCtx);
@@ -460,6 +465,15 @@ function AssistantChangedFilesSectionInner({
465
: null,
466
);
467
const onFileContextMenu = useFileContextMenuHandler(ctx.activeThreadEnvironmentId);
468
+ const repositoryRoot = useAtomValue(
469
+ ctx.workspaceRoot
470
+ ? vcsEnvironment.status({
471
+ environmentId: ctx.activeThreadEnvironmentId,
472
+ input: { cwd: ctx.workspaceRoot },
473
+ })
474
+ : NO_VCS_STATUS,
475
+ (status) => AsyncResult.getOrElse(status, () => null)?.workingTree.rootPath,
476
+ );
477
478
return (
479
<ChangedFilesCard
@@ -479,9 +493,10 @@ function AssistantChangedFilesSectionInner({
493
filePath,
494
workspaceRoot: ctx.workspaceRoot,
495
repositoryRoot:
482
- thread?.worktreePath == null
496
+ repositoryRoot ??
497
+ (thread?.worktreePath == null
498
? activeProject?.repositoryIdentity?.rootPath
484
- : undefined,
499
+ : undefined),
500
},
501
event,
502
)
apps/web/src/diffFileActions.test.ts
+34
-9
@@ -45,15 +45,39 @@ describe("openDiffFilePrimaryAction", () => {
45
).toBe("frontend/Dockerfile");
46
});
47
48
- it("handles Windows roots and mixed diff separators", () => {
49
- expect(
50
- resolveDiffPathForWorkspace({
51
- filePath: "Frontend/src\\index.ts",
52
- workspaceRoot: "C:\\repo\\frontend",
53
- repositoryRoot: "C:\\repo",
54
- }),
55
- ).toBe("src/index.ts");
56
- });
48
+ it.each([
49
+ {
50
+ filePath: "Frontend/src\\index.ts",
51
+ workspaceRoot: "C:\\repo\\frontend",
52
+ repositoryRoot: "C:\\repo",
53
+ expected: "src/index.ts",
54
+ },
55
+ {
56
+ filePath: "Frontend\\src\\index.ts",
57
+ workspaceRoot: "C:\\repo\\frontend",
58
+ repositoryRoot: "C:\\repo",
59
+ expected: "src/index.ts",
60
+ },
61
+ {
62
+ filePath: "frontend/back\\slash.txt",
63
+ workspaceRoot: "/repo/frontend",
64
+ repositoryRoot: "/repo",
65
+ expected: "back\\slash.txt",
66
+ },
67
+ {
68
+ filePath: "back/slash/a.ts",
69
+ workspaceRoot: "/repo/back\\slash",
70
+ repositoryRoot: "/repo",
71
+ expected: null,
72
+ },
73
+ ])(
74
+ "resolves $filePath in $workspaceRoot",
75
+ ({ filePath, workspaceRoot, repositoryRoot, expected }) => {
76
+ expect(resolveDiffPathForWorkspace({ filePath, workspaceRoot, repositoryRoot })).toBe(
77
+ expected,
78
+ );
79
+ },
80
+ );
81
82
// regression: #6174 opening diff files broke for repositories at a filesystem root
83
it.each([
@@ -89,6 +113,7 @@ describe("openDiffFilePrimaryAction", () => {
113
"backend/server.ts",
114
"frontend2/app.ts",
115
"frontend/../secret.ts",
116
+ "frontend/..\\secret.ts",
117
"C:secret.ts",
118
"/repo/backend/server.ts",
119
"/repo/frontend/../backend/server.ts",
apps/web/src/diffFileActions.ts
+20
-13
@@ -17,16 +17,22 @@ interface OpenDiffFilePrimaryActionInput {
17
readonly openInEditor: (targetPath: string) => void;
18
}
19
20
-function normalizedRelativePathSegments(filePath: string): ReadonlyArray<string> | null {
20
+function normalizedRelativePathSegments(
21
+ filePath: string,
22
+ windowsRoot: boolean,
23
+): ReadonlyArray<string> | null {
24
if (filePath.startsWith("/") || isWindowsAbsolutePath(filePath) || /^[a-zA-Z]:/.test(filePath)) {
25
return null;
26
}
27
25
- const segments = filePath
26
- .replaceAll("\\", "/")
27
- .split("/")
28
- .filter((segment) => segment.length > 0 && segment !== ".");
29
- if (segments.length === 0 || segments.includes("..")) return null;
28
+ // On POSIX a backslash is part of a file name; Windows treats it as a separator
29
+ // (tool-call patches can name files with either), so reject ".." either way.
30
+ const parts = filePath.split(/[\\/]/);
31
+ if (parts.includes("..")) return null;
32
+ const segments = (windowsRoot ? parts : filePath.split("/")).filter(
33
+ (segment) => segment.length > 0 && segment !== ".",
34
+ );
35
+ if (segments.length === 0) return null;
36
return segments;
37
}
38
@@ -40,16 +46,13 @@ function repositoryRelativeWorkspaceSegments(
46
const normalizedRepositoryRoot = normalizeProjectPathForComparison(repositoryRoot);
47
if (normalizedWorkspaceRoot === normalizedRepositoryRoot) return [];
48
43
- const separator = normalizedRepositoryRoot.includes("\\") ? "\\" : "/";
49
+ const separator = isWindowsAbsolutePath(normalizedRepositoryRoot) ? "\\" : "/";
50
const repositoryPrefix = normalizedRepositoryRoot.endsWith(separator)
51
? normalizedRepositoryRoot
52
: `${normalizedRepositoryRoot}${separator}`;
53
if (!normalizedWorkspaceRoot.startsWith(repositoryPrefix)) return null;
54
49
- return normalizedWorkspaceRoot
50
- .slice(repositoryPrefix.length)
51
- .split(/[\\/]+/)
52
- .filter(Boolean);
55
+ return normalizedWorkspaceRoot.slice(repositoryPrefix.length).split(separator).filter(Boolean);
56
}
57
58
export function resolveDiffPathForWorkspace(input: {
@@ -57,14 +60,18 @@ export function resolveDiffPathForWorkspace(input: {
60
readonly workspaceRoot: string | undefined;
61
readonly repositoryRoot: string | undefined;
62
}): string | null {
63
+ const windowsRoot = [input.workspaceRoot, input.repositoryRoot].some(
64
+ (root) => root !== undefined && isWindowsAbsolutePath(root),
65
+ );
66
// Claude and ACP tool-call diffs name files by absolute path.
67
if (isAbsolutePath(input.filePath)) {
68
const relativePath = workspaceRelativeFilePath(input.filePath, input.workspaceRoot);
63
- const segments = relativePath === null ? null : normalizedRelativePathSegments(relativePath);
69
+ const segments =
70
+ relativePath === null ? null : normalizedRelativePathSegments(relativePath, windowsRoot);
71
return segments ? segments.join("/") : null;
72
}
73
67
- const fileSegments = normalizedRelativePathSegments(input.filePath);
74
+ const fileSegments = normalizedRelativePathSegments(input.filePath, windowsRoot);
75
if (!fileSegments) return null;
76
77
const workspaceSegments = repositoryRelativeWorkspaceSegments(