* Converts a root URI to a normalized directory path with basic security validation. * @param rootUri - File URI (file://...) or plain directory path * @returns Promise resolving to validated path or null if invalid
(rootUri: string)
| 11 | * @returns Promise resolving to validated path or null if invalid |
| 12 | */ |
| 13 | async function parseRootUri(rootUri: string): Promise<string | null> { |
| 14 | try { |
| 15 | const rawPath = rootUri.startsWith('file://') ? fileURLToPath(rootUri) : rootUri; |
| 16 | const expandedPath = rawPath.startsWith('~/') || rawPath === '~' |
| 17 | ? path.join(os.homedir(), rawPath.slice(1)) |
| 18 | : rawPath; |
| 19 | const absolutePath = path.resolve(expandedPath); |
| 20 | const resolvedPath = await fs.realpath(absolutePath); |
| 21 | return normalizePath(resolvedPath); |
| 22 | } catch { |
| 23 | return null; // Path doesn't exist or other error |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Formats error message for directory validation failures. |
no test coverage detected