diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d6e8e816..93fdf9b17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ This changelog records changes to stable releases since 1.50.2. "TBA" changes he ## Nightly Only -Nothing (yet) +- fix: update path handling when debugging vscode webviews ([ref](https://github.com/microsoft/vscode/issues/133867)) ## v1.61 (September 2021) diff --git a/src/common/urlUtils.ts b/src/common/urlUtils.ts index f13ce7ae3..90f747ffc 100644 --- a/src/common/urlUtils.ts +++ b/src/common/urlUtils.ts @@ -214,13 +214,20 @@ export function stripTrailingSlash(aPath: string): string { return aPath.replace(/\/$/, '').replace(/\\$/, ''); } +const vscodeWebviewResourceSchemeRe = + /^https:\/\/([a-z0-9\-]+)\+\.vscode-resource\.vscode-webview\.net\/(.+)/i; + /** * If urlOrPath is a file URL, removes the 'file:///', adjusting for platform differences */ export function fileUrlToAbsolutePath(urlOrPath: FileUrl): string; export function fileUrlToAbsolutePath(urlOrPath: string): string | undefined; export function fileUrlToAbsolutePath(urlOrPath: string): string | undefined { - if (isVSCodeWebviewUrl(urlOrPath)) { + const webviewResource = vscodeWebviewResourceSchemeRe.exec(urlOrPath); + if (webviewResource) { + urlOrPath = `${webviewResource[1]}:///${webviewResource[2]}`; + } else if (urlOrPath.startsWith('vscode-webview-resource://')) { + // todo@connor4312: is this still in use? const url = new URL(urlOrPath); // Strip off vscode webview url part: vscode-webview-resource://<36-char-guid>/file... urlOrPath = url.pathname @@ -232,9 +239,7 @@ export function fileUrlToAbsolutePath(urlOrPath: string): string | undefined { return `${scheme}://`; // Url has own authority. } }); - } - - if (!isFileUrl(urlOrPath)) { + } else if (!isFileUrl(urlOrPath)) { return undefined; } @@ -399,13 +404,6 @@ export function isFileUrl(candidate: string): candidate is FileUrl { return candidate.startsWith('file:///'); } -/** - * Returns whether the string is a file URL - */ -export function isVSCodeWebviewUrl(candidate: string): candidate is FileUrl { - return candidate.startsWith('vscode-webview-resource://'); -} - export function maybeAbsolutePathToFileUrl( rootPath: string | undefined, sourceUrl: string,