fix(shared): normalize a bare Windows drive root the same as C:\ / C:/ (#6189)

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
This commit is contained in:
Arham AminandClaude Opus 4.8 authored and GitHub committed 2026-08-11 15:52:23 +00:00
1 parent b30a9bc414
commit 6befe42eb0
2 files changed
+17 -1

No files matched your search

+12
View File
@@ -4,6 +4,8 @@ import {
isUncPath,
isWindowsAbsolutePath,
isWindowsDrivePath,
normalizeProjectPathForComparison,
normalizeProjectPathForDispatch,
} from "./path.ts";
describe("path helpers", () => {
@@ -31,4 +33,14 @@ describe("path helpers", () => {
expect(isExplicitRelativePath("..\\repo")).toBe(true);
expect(isExplicitRelativePath("~/repo")).toBe(false);
});
it("normalizes a bare Windows drive root the same as one with a trailing separator", () => {
// `C:`, `C:\` and `C:/` all refer to the drive root and must compare equal.
expect(normalizeProjectPathForDispatch("C:")).toBe("C:\\");
expect(normalizeProjectPathForComparison("C:")).toBe("c:\\");
expect(normalizeProjectPathForComparison("C:")).toBe(normalizeProjectPathForComparison("C:\\"));
expect(normalizeProjectPathForComparison("C:")).toBe(normalizeProjectPathForComparison("C:/"));
// Non-root drive paths keep their trailing separator trimmed as before.
expect(normalizeProjectPathForDispatch("C:\\repo\\")).toBe("C:\\repo");
});
});
+5 -1
View File
@@ -22,7 +22,11 @@ export function isExplicitRelativePath(value: string): boolean {
}
function isRootPath(value: string): boolean {
return value === "/" || value === "\\" || /^[a-zA-Z]:[/\\]?$/.test(value);
// The drive separator is required: a bare `C:` is not the drive root (it
// means "current directory on C:"), and treating it as already-canonical
// would leave it as `C:` while `C:\` and `C:/` normalize to the drive root,
// so the same location would fail project identity/dedup comparisons.
return value === "/" || value === "\\" || /^[a-zA-Z]:[/\\]$/.test(value);
}
function trimTrailingPathSeparators(value: string): string {