Skip to content

Commit

Permalink
Encode webview state when injecting it into the webview
Browse files Browse the repository at this point in the history
Fixes #101321

This should make sure we handle cases where the state string contains special characters, such as `<`
  • Loading branch information
mjbvz committed Jul 6, 2020
1 parent 06c3abf commit 895f03e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/vs/workbench/contrib/webview/browser/pre/main.js
Expand Up @@ -135,13 +135,14 @@
* @return {string}
*/
function getVsCodeApiScript(allowMultipleAPIAcquire, state) {
const encodedState = state ? encodeURIComponent(JSON.stringify(state)) : undefined;
return `
const acquireVsCodeApi = (function() {
const originalPostMessage = window.parent.postMessage.bind(window.parent);
const targetOrigin = '*';
let acquired = false;
let state = ${state ? `JSON.parse(${JSON.stringify(state)})` : undefined};
let state = ${state ? `JSON.parse(decodeURIComponent("${encodedState}"))` : undefined};
return () => {
if (acquired && !${allowMultipleAPIAcquire}) {
Expand Down

0 comments on commit 895f03e

Please sign in to comment.