mirror of
https://github.com/Microsoft/vscode
synced 2024-10-12 14:30:13 +00:00
Fixes regression: cannot open image with special characters '#', '?', '%' (#102189)
* Fixes #102188 * Add unit test for #102188
This commit is contained in:
parent
519ce367a3
commit
86c04f72be
|
@ -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() });
|
||||
|
|
BIN
extensions/vscode-api-tests/testWorkspace/image%02.png
Normal file
BIN
extensions/vscode-api-tests/testWorkspace/image%02.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 25 KiB |
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue