From 93e036cc439e566eac9ee490836f5495e096896c Mon Sep 17 00:00:00 2001 From: Arif Celebi Date: Sun, 1 Mar 2026 10:59:19 +0000 Subject: [PATCH] fix(filesystem): ensure bare Windows drive letters normalize to root Previously, ormalizePath('C:') returned C:. on Windows, which could break path validation. By appending a separator before normalization for bare drive letters, we ensure they consistently resolve to the drive root (e.g., C:\). Fixes #3418 --- src/filesystem/path-utils.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/filesystem/path-utils.ts b/src/filesystem/path-utils.ts index 50910b995b..6ce14f1f07 100644 --- a/src/filesystem/path-utils.ts +++ b/src/filesystem/path-utils.ts @@ -1,4 +1,4 @@ -import path from "path"; +import path from "path"; import os from 'os'; /** @@ -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; } +