From 93e036cc439e566eac9ee490836f5495e096896c Mon Sep 17 00:00:00 2001 From: Arif Celebi Date: Sun, 1 Mar 2026 10:59:19 +0000 Subject: [PATCH 1/2] 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; } + From 206fdb79be754afb9231d4d5779d23318a01438b Mon Sep 17 00:00:00 2001 From: Arif Celebi Date: Sun, 15 Mar 2026 23:09:01 +0000 Subject: [PATCH 2/2] fix(filesystem): remove BOM and cover bare drive roots --- src/filesystem/__tests__/path-utils.test.ts | 11 +++++++++++ src/filesystem/path-utils.ts | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/filesystem/__tests__/path-utils.test.ts b/src/filesystem/__tests__/path-utils.test.ts index 5530cba1c3..3f6072377b 100644 --- a/src/filesystem/__tests__/path-utils.test.ts +++ b/src/filesystem/__tests__/path-utils.test.ts @@ -354,6 +354,17 @@ describe('Path Utilities', () => { expect(result).not.toContain('\\'); }); + it('normalizes bare Windows drive letters to the drive root on Windows', () => { + Object.defineProperty(process, 'platform', { + value: 'win32', + writable: true, + configurable: true + }); + + expect(normalizePath('C:')).toBe('C:\\'); + expect(normalizePath('d:')).toBe('D:\\'); + }); + it('should handle relative path slash conversion based on platform', () => { // This test verifies platform-specific behavior naturally without mocking // On Windows: forward slashes converted to backslashes diff --git a/src/filesystem/path-utils.ts b/src/filesystem/path-utils.ts index 6ce14f1f07..6ab5a5969b 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'; /**