Skip to content

Commit

Permalink
Fix loading of webview resources that depend on query params
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mjbvz committed Apr 13, 2021
1 parent eac3821 commit 48387df
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
});

Expand Down

0 comments on commit 48387df

Please sign in to comment.