Fix loading of webview resources that depend on query params

Some resource url (notably git) use the query part of the url to store additional information. The query part of the url was incorrectly being dropped while attempting to load these resources inside of webviews
This commit is contained in:
Matt Bierner 2021-04-12 21:31:30 -07:00
parent eac3821fbf
commit 48387dfc3d
No known key found for this signature in database
GPG key ID: 099C331567E11888
2 changed files with 5 additions and 2 deletions

View file

@ -210,10 +210,12 @@ export abstract class BaseWebview<T extends HTMLElement> extends Disposable {
this.handleKeyEvent('keyup', data);
}));
this._register(this.on(WebviewMessageChannels.loadResource, (entry: any) => {
this._register(this.on(WebviewMessageChannels.loadResource, (entry: { id: number, path: string, query: string, ifNoneMatch?: string }) => {
const rawPath = entry.path;
const normalizedPath = decodeURIComponent(rawPath);
const uri = URI.parse(normalizedPath.replace(/^\/([\w\-]+)\/(.+)$/, (_, scheme, path) => scheme + ':/' + path));
const uri = URI.parse(normalizedPath.replace(/^\/([\w\-]+)\/(.+)$/, (_, scheme, path) => scheme + ':/' + path)).with({
query: decodeURIComponent(entry.query),
});
this.loadResource(entry.id, rawPath, uri, entry.ifNoneMatch);
}));

View file

@ -255,6 +255,7 @@ async function processResourceRequest(event, requestUrl) {
channel: 'load-resource',
id: requestId,
path: resourcePath,
query: requestUrl.search.replace(/^\?/, ''),
ifNoneMatch: cached?.headers.get('ETag'),
});