(path: string, basePath = MockHomePath)
| 62 | }; |
| 63 | |
| 64 | function normalizeMockPath(path: string, basePath = MockHomePath): string { |
| 65 | if (path == null || path === "") { |
| 66 | return basePath; |
| 67 | } |
| 68 | if (path.startsWith("wsh://")) { |
| 69 | const url = new URL(path); |
| 70 | path = url.pathname.replace(/^\/+/, "/"); |
| 71 | } |
| 72 | if (path === "~") { |
| 73 | path = MockHomePath; |
| 74 | } else if (path.startsWith("~/")) { |
| 75 | path = MockHomePath + path.slice(1); |
| 76 | } |
| 77 | if (!path.startsWith("/")) { |
| 78 | path = `${basePath}/${path}`; |
| 79 | } |
| 80 | const parts = path.split("/"); |
| 81 | const resolvedParts: string[] = []; |
| 82 | for (const part of parts) { |
| 83 | if (!part || part === ".") { |
| 84 | continue; |
| 85 | } |
| 86 | if (part === "..") { |
| 87 | resolvedParts.pop(); |
| 88 | continue; |
| 89 | } |
| 90 | resolvedParts.push(part); |
| 91 | } |
| 92 | const resolvedPath = "/" + resolvedParts.join("/"); |
| 93 | return resolvedPath === "" ? "/" : resolvedPath; |
| 94 | } |
| 95 | |
| 96 | function getDirName(path: string): string { |
| 97 | if (path === "/") { |
no test coverage detected