(urlOrPath: string)
| 259 | export function fileUrlToAbsolutePath(urlOrPath: FileUrl): string; |
| 260 | export function fileUrlToAbsolutePath(urlOrPath: string): string | undefined; |
| 261 | export function fileUrlToAbsolutePath(urlOrPath: string): string | undefined { |
| 262 | const webviewResource = vscodeWebviewResourceSchemeRe.exec(urlOrPath); |
| 263 | if (webviewResource) { |
| 264 | urlOrPath = `${webviewResource[1]}:///${webviewResource[2]}`; |
| 265 | } else if (urlOrPath.startsWith('vscode-webview-resource://')) { |
| 266 | // todo@connor4312: is this still in use? |
| 267 | const url = new URL(urlOrPath); |
| 268 | // Strip off vscode webview url part: vscode-webview-resource://<36-char-guid>/file... |
| 269 | urlOrPath = url.pathname |
| 270 | .replace(/%2F/gi, '/') |
| 271 | .replace(/^\/([a-z0-9\-]+)(\/{1,2})/i, (_: string, scheme: string, sep: string) => { |
| 272 | if (sep.length === 1) { |
| 273 | return `${scheme}:///`; // Add empty authority. |
| 274 | } else { |
| 275 | return `${scheme}://`; // Url has own authority. |
| 276 | } |
| 277 | }); |
| 278 | } else if (urlOrPath.startsWith(vscodeAppResource)) { |
| 279 | urlOrPath = urlOrPath.slice(vscodeAppResource.length); |
| 280 | } else if (!isFileUrl(urlOrPath)) { |
| 281 | return undefined; |
| 282 | } |
| 283 | |
| 284 | urlOrPath = urlOrPath.replace('file:///', ''); |
| 285 | urlOrPath = decodeURIComponent(urlOrPath); |
| 286 | |
| 287 | // UNC paths are returned from Chrome in the form `file:////shared/folder`, |
| 288 | // rather than `file:///`. This is not _entirely_ prescriptive since some |
| 289 | // applications can use four slashes for posix paths as well (even though V8 |
| 290 | // doesn't seem to), so only do this if the debugger is currently running on Windows. |
| 291 | if (urlOrPath.startsWith('/') && process.platform === 'win32') { |
| 292 | if (urlOrPath[1] !== '/') { |
| 293 | urlOrPath = '/' + urlOrPath; // restore extra slash |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | if (urlOrPath[0] !== '/' && !urlOrPath.match(/^[A-Za-z]:/)) { |
| 298 | // If it has a : before the first /, assume it's a windows path or url. |
| 299 | // Ensure unix-style path starts with /, it can be removed when file:/// was stripped. |
| 300 | // Don't add if the url still has a protocol |
| 301 | urlOrPath = '/' + urlOrPath; |
| 302 | } |
| 303 | |
| 304 | return fixDriveLetterAndSlashes(urlOrPath); |
| 305 | } |
| 306 | |
| 307 | /** |
| 308 | * Converts a file URL to a windows network path, if possible. |
no test coverage detected