mirror of
https://github.com/modelcontextprotocol/servers.git
synced 2026-04-17 15:43:24 +02:00
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:
@@ -354,6 +354,17 @@ describe('Path Utilities', () => {
|
|||||||
expect(result).not.toContain('\\');
|
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', () => {
|
it('should handle relative path slash conversion based on platform', () => {
|
||||||
// This test verifies platform-specific behavior naturally without mocking
|
// This test verifies platform-specific behavior naturally without mocking
|
||||||
// On Windows: forward slashes converted to backslashes
|
// On Windows: forward slashes converted to backslashes
|
||||||
|
|||||||
@@ -77,6 +77,12 @@ export function normalizePath(p: string): string {
|
|||||||
p = p.replace(/\\\\/g, '\\');
|
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
|
// Use Node's path normalization, which handles . and .. segments
|
||||||
let normalized = path.normalize(p);
|
let normalized = path.normalize(p);
|
||||||
|
|
||||||
@@ -116,3 +122,4 @@ export function expandHome(filepath: string): string {
|
|||||||
}
|
}
|
||||||
return filepath;
|
return filepath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user