Fixes regression: cannot open image with special characters '#', '?', '%' (#102189)

* Fixes #102188

* Add unit test for #102188
This commit is contained in:
Jean Pierre 2020-07-24 15:58:54 -05:00 committed by GitHub
parent 519ce367a3
commit 86c04f72be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 1 deletions

View file

@ -272,6 +272,12 @@ suite('vscode API - webview', () => {
const response = await sendRecieveMessage(webview, { src: imagePath.toString() });
assert.strictEqual(response.value, true);
}
{
// #102188. Resource filename containing special characters like '%', '#', '?'.
const imagePath = webview.webview.asWebviewUri(workspaceFile('image%02.png'));
const response = await sendRecieveMessage(webview, { src: imagePath.toString() });
assert.strictEqual(response.value, true);
}
{
const imagePath = webview.webview.asWebviewUri(workspaceFile('no-such-image.png'));
const response = await sendRecieveMessage(webview, { src: imagePath.toString() });

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

View file

@ -99,7 +99,9 @@ function normalizeRequestPath(requestUri: URI) {
//
// vscode-webview-resource://id/scheme//authority?/path
//
const resourceUri = URI.parse(requestUri.path.replace(/^\/([a-z0-9\-]+)(\/{1,2})/i, (_: string, scheme: string, sep: string) => {
// Encode requestUri.path so that URI.parse can properly parse special characters like '#', '?', etc.
const resourceUri = URI.parse(encodeURIComponent(requestUri.path).replace(/%2F/g, '/').replace(/^\/([a-z0-9\-]+)\/{1,2}/i, (_: string, scheme: string, sep: string) => {
if (sep.length === 1) {
return `${scheme}:///`; // Add empty authority.
} else {