11import { expect } from "chai" ;
2+ import * as path from "path" ;
23import * as tmp from "tmp" ;
34import { window , ViewColumn , Uri } from "vscode" ;
45import { fileUriToWebviewUri , webviewUriToFileUri } from '../../interface' ;
56
67describe ( '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