Skip to content

Commit 93e036c

Browse files
committed
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 modelcontextprotocol#3418
1 parent 72efc42 commit 93e036c

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

‎src/filesystem/path-utils.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import path from "path";
1+
import path from "path";
22
import os from 'os';
33

44
/**
@@ -77,6 +77,12 @@ export function normalizePath(p: string): string {
7777
p = p.replace(/\\\\/g, '\\');
7878
}
7979

80+
// On Windows, if we have a bare drive letter (e.g. "C:"), append a separator
81+
// so path.normalize doesn't return "C:." which can break path validation.
82+
if (process.platform === 'win32' && /^[a-zA-Z]:$/.test(p)) {
83+
p = p + path.sep;
84+
}
85+
8086
// Use Node's path normalization, which handles . and .. segments
8187
let normalized = path.normalize(p);
8288

@@ -116,3 +122,4 @@ export function expandHome(filepath: string): string {
116122
}
117123
return filepath;
118124
}
125+

0 commit comments

Comments
 (0)