Skip to content

Commit 002dc9b

Browse files
fix(web): file names with a backslash no longer split into folders in the Changes card (pingdotgg#35075)
1 parent 4ff329d commit 002dc9b

2 files changed

Lines changed: 31 additions & 4 deletions

File tree

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,34 @@ describe("buildTurnDiffTree", () => {
138138
},
139139
]);
140140
});
141+
142+
it("keeps a literal backslash in a POSIX file name instead of splitting it into a folder", () => {
143+
expect(
144+
buildTurnDiffTree([
145+
{ path: "back\\slash.txt", kind: "modified", additions: 1, deletions: 0 },
146+
{ path: "back/slash.txt", kind: "modified", additions: 2, deletions: 0 },
147+
]),
148+
).toEqual([
149+
{
150+
kind: "directory",
151+
name: "back",
152+
path: "back",
153+
stat: { additions: 2, deletions: 0 },
154+
children: [
155+
{
156+
kind: "file",
157+
name: "slash.txt",
158+
path: "back/slash.txt",
159+
stat: { additions: 2, deletions: 0 },
160+
},
161+
],
162+
},
163+
{
164+
kind: "file",
165+
name: "back\\slash.txt",
166+
path: "back\\slash.txt",
167+
stat: { additions: 1, deletions: 0 },
168+
},
169+
]);
170+
});
141171
});

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ interface MutableDirectoryNode {
3333
let sortCollator: Intl.Collator | undefined;
3434

3535
function normalizePathSegments(pathValue: string): string[] {
36-
return pathValue
37-
.replaceAll("\\", "/")
38-
.split("/")
39-
.filter((segment) => segment.length > 0);
36+
return pathValue.split("/").filter((segment) => segment.length > 0);
4037
}
4138

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

0 commit comments

Comments
 (0)