diff --git a/apps/web/src/lib/turnDiffTree.test.ts b/apps/web/src/lib/turnDiffTree.test.ts index bf792a803238c..15340c8e8bfdf 100644 --- a/apps/web/src/lib/turnDiffTree.test.ts +++ b/apps/web/src/lib/turnDiffTree.test.ts @@ -138,4 +138,34 @@ describe("buildTurnDiffTree", () => { }, ]); }); + + it("keeps a literal backslash in a POSIX file name instead of splitting it into a folder", () => { + expect( + buildTurnDiffTree([ + { path: "back\\slash.txt", kind: "modified", additions: 1, deletions: 0 }, + { path: "back/slash.txt", kind: "modified", additions: 2, deletions: 0 }, + ]), + ).toEqual([ + { + kind: "directory", + name: "back", + path: "back", + stat: { additions: 2, deletions: 0 }, + children: [ + { + kind: "file", + name: "slash.txt", + path: "back/slash.txt", + stat: { additions: 2, deletions: 0 }, + }, + ], + }, + { + kind: "file", + name: "back\\slash.txt", + path: "back\\slash.txt", + stat: { additions: 1, deletions: 0 }, + }, + ]); + }); }); diff --git a/apps/web/src/lib/turnDiffTree.ts b/apps/web/src/lib/turnDiffTree.ts index 7d491e15ccfb5..7cceba0137847 100644 --- a/apps/web/src/lib/turnDiffTree.ts +++ b/apps/web/src/lib/turnDiffTree.ts @@ -33,10 +33,7 @@ interface MutableDirectoryNode { let sortCollator: Intl.Collator | undefined; function normalizePathSegments(pathValue: string): string[] { - return pathValue - .replaceAll("\\", "/") - .split("/") - .filter((segment) => segment.length > 0); + return pathValue.split("/").filter((segment) => segment.length > 0); } function compareByName(a: { name: string }, b: { name: string }): number {