Skip to content

Commit 2428087

Browse files
only21milclaude
andcommitted
fix(web): preserve literal backslashes in changed-file paths
Checkpoint paths come from Git numstat, which separates directories with "/" on every platform. The changed-files tree also split on "\", so a POSIX file named back\slash.txt showed under a false "back" folder and shared the identity of back/slash.txt, opening the wrong diff. Split only on "/" and keep the card's folder check in line. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 05696c6 commit 2428087

3 files changed

Lines changed: 34 additions & 5 deletions

File tree

‎apps/web/src/components/chat/ChangedFilesTree.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const ChangedFilesCard = memo(function ChangedFilesCard(props: {
4747
onFileContextMenu,
4848
} = props;
4949
const summaryStat = summarizeTurnDiffStats(files);
50-
const hasDirectories = files.some((file) => /[/\\]/.test(file.path));
50+
const hasDirectories = files.some((file) => file.path.includes("/"));
5151

5252
return (
5353
<div

‎apps/web/src/lib/turnDiffTree.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,34 @@ describe("buildTurnDiffTree", () => {
8585
},
8686
]);
8787
});
88+
89+
it("keeps literal backslashes in file names apart from directory paths", () => {
90+
const tree = buildTurnDiffTree([
91+
{ path: "back\\slash.txt", kind: "modified", additions: 1, deletions: 0 },
92+
{ path: "back/slash.txt", kind: "modified", additions: 2, deletions: 0 },
93+
]);
94+
95+
expect(tree).toEqual([
96+
{
97+
kind: "directory",
98+
name: "back",
99+
path: "back",
100+
stat: { additions: 2, deletions: 0 },
101+
children: [
102+
{
103+
kind: "file",
104+
name: "slash.txt",
105+
path: "back/slash.txt",
106+
stat: { additions: 2, deletions: 0 },
107+
},
108+
],
109+
},
110+
{
111+
kind: "file",
112+
name: "back\\slash.txt",
113+
path: "back\\slash.txt",
114+
stat: { additions: 1, deletions: 0 },
115+
},
116+
]);
117+
});
88118
});

‎apps/web/src/lib/turnDiffTree.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@ interface MutableDirectoryNode {
3232

3333
const SORT_LOCALE_OPTIONS: Intl.CollatorOptions = { numeric: true, sensitivity: "base" };
3434

35+
// Checkpoint paths come from Git, which separates directories with "/" on every
36+
// platform. A backslash is part of a POSIX file name, not a separator.
3537
function normalizePathSegments(pathValue: string): string[] {
36-
return pathValue
37-
.replaceAll("\\", "/")
38-
.split("/")
39-
.filter((segment) => segment.length > 0);
38+
return pathValue.split("/").filter((segment) => segment.length > 0);
4039
}
4140

4241
function compareByName(a: { name: string }, b: { name: string }): number {

0 commit comments

Comments
 (0)