fix(filesystem): ensure bare Windows drive letters normalize to root (#3434)

fix(filesystem): ensure bare Windows drive letters normalize to root

Appends path.sep to bare drive letters (e.g. "C:") before calling path.normalize(), preventing them from normalizing to "C:." (current directory on drive) instead of "C:\" (drive root). Includes test coverage with platform mocking.

Fixes #3418
This commit is contained in:
Arif Celebi
2026-03-16 19:12:00 +00:00
committed by GitHub
parent 1cdf806d21
commit b60eca1b3b
2 changed files with 18 additions and 0 deletions

View File

@@ -77,6 +77,12 @@ export function normalizePath(p: string): string {
p = p.replace(/\\\\/g, '\\');
}
// On Windows, if we have a bare drive letter (e.g. "C:"), append a separator
// so path.normalize doesn't return "C:." which can break path validation.
if (process.platform === 'win32' && /^[a-zA-Z]:$/.test(p)) {
p = p + path.sep;
}
// Use Node's path normalization, which handles . and .. segments
let normalized = path.normalize(p);
@@ -116,3 +122,4 @@ export function expandHome(filepath: string): string {
}
return filepath;
}