fix(filesystem): use fileURLToPath for Windows absolute path parsing (#3205)
This commit is contained in:
parent
6a914b9db8
commit
1b96551ef0
1 changed files with 2 additions and 1 deletions
|
|
@ -3,6 +3,7 @@ import path from 'path';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
import { normalizePath } from './path-utils.js';
|
import { normalizePath } from './path-utils.js';
|
||||||
import type { Root } from '@modelcontextprotocol/sdk/types.js';
|
import type { Root } from '@modelcontextprotocol/sdk/types.js';
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a root URI to a normalized directory path with basic security validation.
|
* Converts a root URI to a normalized directory path with basic security validation.
|
||||||
|
|
@ -11,7 +12,7 @@ import type { Root } from '@modelcontextprotocol/sdk/types.js';
|
||||||
*/
|
*/
|
||||||
async function parseRootUri(rootUri: string): Promise<string | null> {
|
async function parseRootUri(rootUri: string): Promise<string | null> {
|
||||||
try {
|
try {
|
||||||
const rawPath = rootUri.startsWith('file://') ? rootUri.slice(7) : rootUri;
|
const rawPath = rootUri.startsWith('file://') ? fileURLToPath(rootUri) : rootUri;
|
||||||
const expandedPath = rawPath.startsWith('~/') || rawPath === '~'
|
const expandedPath = rawPath.startsWith('~/') || rawPath === '~'
|
||||||
? path.join(os.homedir(), rawPath.slice(1))
|
? path.join(os.homedir(), rawPath.slice(1))
|
||||||
: rawPath;
|
: rawPath;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue