mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-20 02:08:47 +00:00
Rewrite webview urls to be more url-ish
## Problem Webview uris currently have the form: ``` https://uuid.vscode-webview.net/vscode-resource/scheme/authority/path... ``` We have this syntax because we need to be able to recover the original scheme and authority of the resource in order to load it from disk However this syntax means that absolute urls don't behave as you'd expect. For example, if you have a webview that sets a `<base>` to a document in the workspace, an absolute url `/abs/path.png` ends up being resolved to: ``` https://uuid.vscode-webview.net/abs/path.png ``` This drops the original scheme and authority, which prevents us from loading the resource ## Fix With this change, I've moved the original scheme and authority into the authority of the webview uri instead of the path: ``` https://scheme+authority.vscode-resource.uuid.vscode-webview.net/path... ``` With this change, absolute paths should correctly be resolved
This commit is contained in:
@@ -269,14 +269,12 @@ export class MarkdownEngine {
|
||||
if (uri.path[0] === '/') {
|
||||
const root = vscode.workspace.getWorkspaceFolder(this.currentDocument!);
|
||||
if (root) {
|
||||
const fileUri = vscode.Uri.joinPath(root.uri, uri.fsPath).with({
|
||||
uri = vscode.Uri.joinPath(root.uri, uri.fsPath).with({
|
||||
fragment: uri.fragment,
|
||||
query: uri.query,
|
||||
}).with({
|
||||
scheme: 'markdown-link'
|
||||
});
|
||||
|
||||
// Ensure fileUri is relative by prepending `/` so that it uses the <base> element URI
|
||||
// when resolving the absolute URL
|
||||
uri = vscode.Uri.parse('markdown-link:' + '/' + fileUri.toString(true).replace(/^\S+?:/, fileUri.scheme));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user