Skip to content

Commit 3811b2e

Browse files
committed
Fix double-encoding of "#" in webview URI conversion
This fixes sorting for result sets with a "#" in their name.
1 parent 737fa11 commit 3811b2e

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

extensions/ql-vscode/src/interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function getHtmlForWebview(webview: vscode.Webview, scriptUriOnDisk: vscode.Uri,
7474

7575
/** Converts a filesystem URI into a webview URI string that the given panel can use to read the file. */
7676
export function fileUriToWebviewUri(panel: vscode.WebviewPanel, fileUriOnDisk: Uri): string {
77-
return encodeURI(panel.webview.asWebviewUri(fileUriOnDisk).toString(true));
77+
return panel.webview.asWebviewUri(fileUriOnDisk).toString();
7878
}
7979

8080
/** Converts a URI string received from a webview into a local filesystem URI for the same resource. */

extensions/ql-vscode/src/vscode-tests/no-workspace/webview-uri.test.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { expect } from "chai";
2+
import * as path from "path";
23
import * as tmp from "tmp";
34
import { window, ViewColumn, Uri } from "vscode";
45
import { fileUriToWebviewUri, webviewUriToFileUri } from '../../interface';
56

67
describe('webview uri conversion', function () {
7-
it('should correctly round trip from filesystem to webview and back', function () {
8-
const tmpFile = tmp.fileSync({ prefix: 'uri_test_', postfix: '.bqrs', keep: false });
8+
const fileSuffix = '.bqrs';
9+
10+
function setupWebview(filePrefix: string) {
11+
const tmpFile = tmp.fileSync({ prefix: `uri_test_${filePrefix}_`, postfix: fileSuffix, keep: false });
912
const fileUriOnDisk = Uri.file(tmpFile.name);
1013
const panel = window.createWebviewPanel(
1114
'test panel',
@@ -26,9 +29,23 @@ describe('webview uri conversion', function () {
2629
// CSP allowing nothing, to prevent warnings.
2730
const html = `<html><head><meta http-equiv="Content-Security-Policy" content="default-src 'none';"></head></html>`;
2831
panel.webview.html = html;
29-
32+
return {
33+
fileUriOnDisk,
34+
panel
35+
}
36+
}
37+
38+
it('should correctly round trip from filesystem to webview and back', function () {
39+
const { fileUriOnDisk, panel } = setupWebview('');
3040
const webviewUri = fileUriToWebviewUri(panel, fileUriOnDisk);
3141
const reconstructedFileUri = webviewUriToFileUri(webviewUri);
3242
expect(reconstructedFileUri.toString(true)).to.equal(fileUriOnDisk.toString(true));
3343
});
44+
45+
it("does not double-encode # in URIs", function () {
46+
const { fileUriOnDisk, panel } = setupWebview('#');
47+
const webviewUri = fileUriToWebviewUri(panel, fileUriOnDisk);
48+
const parsedUri = Uri.parse(webviewUri);
49+
expect(path.basename(parsedUri.path, fileSuffix)).to.equal(path.basename(fileUriOnDisk.path, fileSuffix));
50+
});
3451
});

0 commit comments

Comments
 (0)