Skip to content

Commit a1a2d3c

Browse files
only21milclaude
andcommitted
fix(web): open diff files from a workspace whose path has a backslash
A POSIX workspace such as /repo/back\slash was split on "\" too, so its segments never matched Git's back\slash/a.ts and Open did nothing. Split the workspace suffix on the repository root's own separator: "\" for Windows roots, "/" otherwise. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent ecee07d commit a1a2d3c

2 files changed

Lines changed: 35 additions & 24 deletions

File tree

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

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

48-
it("handles Windows roots", () => {
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-
});
57-
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-
});
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\\src",
58+
repositoryRoot: "C:\\repo",
59+
expected: "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: "a.ts",
72+
},
73+
])(
74+
"resolves $filePath in $workspaceRoot",
75+
({ filePath, workspaceRoot, repositoryRoot, expected }) => {
76+
expect(resolveDiffPathForWorkspace({ filePath, workspaceRoot, repositoryRoot })).toBe(
77+
expected,
78+
);
79+
},
80+
);
6781

6882
// regression: #6174 opening diff files broke for repositories at a filesystem root
6983
it.each([

‎apps/web/src/diffFileActions.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,13 @@ function repositoryRelativeWorkspaceSegments(
3535
const normalizedRepositoryRoot = normalizeProjectPathForComparison(repositoryRoot);
3636
if (normalizedWorkspaceRoot === normalizedRepositoryRoot) return [];
3737

38-
const separator = normalizedRepositoryRoot.includes("\\") ? "\\" : "/";
38+
const separator = isWindowsAbsolutePath(normalizedRepositoryRoot) ? "\\" : "/";
3939
const repositoryPrefix = normalizedRepositoryRoot.endsWith(separator)
4040
? normalizedRepositoryRoot
4141
: `${normalizedRepositoryRoot}${separator}`;
4242
if (!normalizedWorkspaceRoot.startsWith(repositoryPrefix)) return null;
4343

44-
return normalizedWorkspaceRoot
45-
.slice(repositoryPrefix.length)
46-
.split(/[\\/]+/)
47-
.filter(Boolean);
44+
return normalizedWorkspaceRoot.slice(repositoryPrefix.length).split(separator).filter(Boolean);
4845
}
4946

5047
export function resolveDiffPathForWorkspace(input: {

0 commit comments

Comments
 (0)