Skip to content

Commit ecee07d

Browse files
only21milclaude
andcommitted
fix(web): Open and Reveal keep literal backslashes in diff paths
The changed-files tree now keeps back\slash.txt apart from back/slash.txt, but resolveDiffPathForWorkspace still turned every backslash into "/", so Open, the context-menu Open and Reveal landed on back/slash.txt. Split Git paths on "/" only and leave the host separator to the path join. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent ba01d33 commit ecee07d

2 files changed

Lines changed: 37 additions & 24 deletions

File tree

‎apps/web/src/diffFileActions.test.ts‎

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,26 @@ describe("openDiffFilePrimaryAction", () => {
4545
).toBe("frontend/Dockerfile");
4646
});
4747

48-
it("handles Windows roots and mixed diff separators", () => {
48+
it("handles Windows roots", () => {
4949
expect(
5050
resolveDiffPathForWorkspace({
51-
filePath: "Frontend/src\\index.ts",
51+
filePath: "Frontend/src/index.ts",
5252
workspaceRoot: "C:\\repo\\frontend",
5353
repositoryRoot: "C:\\repo",
5454
}),
5555
).toBe("src/index.ts");
5656
});
5757

58+
it("keeps a literal backslash in a Git file name", () => {
59+
expect(
60+
resolveDiffPathForWorkspace({
61+
filePath: "frontend/back\\slash.txt",
62+
workspaceRoot: "/repo/frontend",
63+
repositoryRoot: "/repo",
64+
}),
65+
).toBe("back\\slash.txt");
66+
});
67+
5868
// regression: #6174 opening diff files broke for repositories at a filesystem root
5969
it.each([
6070
{ workspaceRoot: "/frontend", repositoryRoot: "/" },
@@ -69,23 +79,26 @@ describe("openDiffFilePrimaryAction", () => {
6979
).toBe("index.ts");
7080
});
7181

72-
it.each(["backend/server.ts", "frontend2/app.ts", "frontend/../secret.ts", "C:secret.ts"])(
73-
"does not open an out-of-project diff path: %s",
74-
(filePath) => {
75-
const openInEditor = vi.fn();
82+
it.each([
83+
"backend/server.ts",
84+
"frontend2/app.ts",
85+
"frontend/../secret.ts",
86+
"frontend/..\\secret.ts",
87+
"C:secret.ts",
88+
])("does not open an out-of-project diff path: %s", (filePath) => {
89+
const openInEditor = vi.fn();
7690

77-
openDiffFilePrimaryAction({
78-
threadRef: THREAD_REF,
79-
filePath,
80-
activeCwd: "/repo/frontend",
81-
repositoryRoot: "/repo",
82-
openInEditor,
83-
});
91+
openDiffFilePrimaryAction({
92+
threadRef: THREAD_REF,
93+
filePath,
94+
activeCwd: "/repo/frontend",
95+
repositoryRoot: "/repo",
96+
openInEditor,
97+
});
8498

85-
expect(
86-
selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, THREAD_REF),
87-
).toMatchObject({ isOpen: false });
88-
expect(openInEditor).not.toHaveBeenCalled();
89-
},
90-
);
99+
expect(
100+
selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, THREAD_REF),
101+
).toMatchObject({ isOpen: false });
102+
expect(openInEditor).not.toHaveBeenCalled();
103+
});
91104
});

‎apps/web/src/diffFileActions.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ function normalizedRelativePathSegments(filePath: string): ReadonlyArray<string>
1717
return null;
1818
}
1919

20-
const segments = filePath
21-
.replaceAll("\\", "/")
22-
.split("/")
23-
.filter((segment) => segment.length > 0 && segment !== ".");
24-
if (segments.length === 0 || segments.includes("..")) return null;
20+
// Git separates directories with "/" on every platform, so a backslash is part of
21+
// a file name. Windows paths still treat it as a separator, so reject ".." either way.
22+
if (filePath.split(/[\\/]/).includes("..")) return null;
23+
const segments = filePath.split("/").filter((segment) => segment.length > 0 && segment !== ".");
24+
if (segments.length === 0) return null;
2525
return segments;
2626
}
2727

0 commit comments

Comments
 (0)