File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44 isUncPath ,
55 isWindowsAbsolutePath ,
66 isWindowsDrivePath ,
7+ normalizeProjectPathForComparison ,
8+ normalizeProjectPathForDispatch ,
79} from "./path.ts" ;
810
911describe ( "path helpers" , ( ) => {
@@ -31,4 +33,14 @@ describe("path helpers", () => {
3133 expect ( isExplicitRelativePath ( "..\\repo" ) ) . toBe ( true ) ;
3234 expect ( isExplicitRelativePath ( "~/repo" ) ) . toBe ( false ) ;
3335 } ) ;
36+
37+ it ( "normalizes a bare Windows drive root the same as one with a trailing separator" , ( ) => {
38+ // `C:`, `C:\` and `C:/` all refer to the drive root and must compare equal.
39+ expect ( normalizeProjectPathForDispatch ( "C:" ) ) . toBe ( "C:\\" ) ;
40+ expect ( normalizeProjectPathForComparison ( "C:" ) ) . toBe ( "c:\\" ) ;
41+ expect ( normalizeProjectPathForComparison ( "C:" ) ) . toBe ( normalizeProjectPathForComparison ( "C:\\" ) ) ;
42+ expect ( normalizeProjectPathForComparison ( "C:" ) ) . toBe ( normalizeProjectPathForComparison ( "C:/" ) ) ;
43+ // Non-root drive paths keep their trailing separator trimmed as before.
44+ expect ( normalizeProjectPathForDispatch ( "C:\\repo\\" ) ) . toBe ( "C:\\repo" ) ;
45+ } ) ;
3446} ) ;
Original file line number Diff line number Diff line change @@ -22,7 +22,11 @@ export function isExplicitRelativePath(value: string): boolean {
2222}
2323
2424function isRootPath ( value : string ) : boolean {
25- return value === "/" || value === "\\" || / ^ [ a - z A - Z ] : [ / \\ ] ? $ / . test ( value ) ;
25+ // The drive separator is required: a bare `C:` is not the drive root (it
26+ // means "current directory on C:"), and treating it as already-canonical
27+ // would leave it as `C:` while `C:\` and `C:/` normalize to the drive root,
28+ // so the same location would fail project identity/dedup comparisons.
29+ return value === "/" || value === "\\" || / ^ [ a - z A - Z ] : [ / \\ ] $ / . test ( value ) ;
2630}
2731
2832function trimTrailingPathSeparators ( value : string ) : string {
You can’t perform that action at this time.
0 commit comments