Skip to content

Commit

Permalink
fix: update path handling when debugging vscode webviews
Browse files Browse the repository at this point in the history
  • Loading branch information
connor4312 committed Oct 6, 2021
1 parent 551929d commit db28686
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
20 changes: 9 additions & 11 deletions src/common/urlUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit db28686

Please sign in to comment.