Skip to content

Commit 0ff92b4

Browse files
only21milclaude
andcommitted
fix(web): diff paths under a Windows root still split on backslashes
Tool-call patches can name files with backslash separators; only POSIX roots keep a backslash as part of a file name. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 68c83ba commit 0ff92b4

2 files changed

Lines changed: 29 additions & 7 deletions

File tree

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ describe("openDiffFilePrimaryAction", () => {
5252
repositoryRoot: "C:\\repo",
5353
expected: "src/index.ts",
5454
},
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\\src\\index.ts",
63+
workspaceRoot: "C:\\repo\\frontend",
64+
repositoryRoot: "C:\\repo",
65+
expected: "src/index.ts",
66+
},
5567
{
5668
filePath: "Frontend/Src/index.ts",
5769
workspaceRoot: "C:\\repo\\frontend\\src",

‎apps/web/src/diffFileActions.ts‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,21 @@ interface OpenDiffFilePrimaryActionInput {
1717
readonly openInEditor: (targetPath: string) => void;
1818
}
1919

20-
function normalizedRelativePathSegments(filePath: string): ReadonlyArray<string> | null {
20+
function normalizedRelativePathSegments(
21+
filePath: string,
22+
windowsRoot: boolean,
23+
): ReadonlyArray<string> | null {
2124
if (filePath.startsWith("/") || isWindowsAbsolutePath(filePath) || /^[a-zA-Z]:/.test(filePath)) {
2225
return null;
2326
}
2427

25-
// Git separates directories with "/" on every platform, so a backslash is part of
26-
// a file name. Windows paths still treat it as a separator, so reject ".." either way.
27-
if (filePath.split(/[\\/]/).includes("..")) return null;
28-
const segments = filePath.split("/").filter((segment) => segment.length > 0 && segment !== ".");
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+
);
2935
if (segments.length === 0) return null;
3036
return segments;
3137
}
@@ -54,14 +60,18 @@ export function resolveDiffPathForWorkspace(input: {
5460
readonly workspaceRoot: string | undefined;
5561
readonly repositoryRoot: string | undefined;
5662
}): string | null {
63+
const windowsRoot = [input.workspaceRoot, input.repositoryRoot].some(
64+
(root) => root !== undefined && isWindowsAbsolutePath(root),
65+
);
5766
// Claude and ACP tool-call diffs name files by absolute path.
5867
if (isAbsolutePath(input.filePath)) {
5968
const relativePath = workspaceRelativeFilePath(input.filePath, input.workspaceRoot);
60-
const segments = relativePath === null ? null : normalizedRelativePathSegments(relativePath);
69+
const segments =
70+
relativePath === null ? null : normalizedRelativePathSegments(relativePath, windowsRoot);
6171
return segments ? segments.join("/") : null;
6272
}
6373

64-
const fileSegments = normalizedRelativePathSegments(input.filePath);
74+
const fileSegments = normalizedRelativePathSegments(input.filePath, windowsRoot);
6575
if (!fileSegments) return null;
6676

6777
const workspaceSegments = repositoryRelativeWorkspaceSegments(

0 commit comments

Comments
 (0)