From 40141e2dfc2fa5b14079aa6ddde7a16cfe854076 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Thu, 1 Jun 2023 08:48:27 -0400 Subject: [PATCH] Fix assembling of scriptlets for isolated world --- src/js/scriptlet-filtering.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/js/scriptlet-filtering.js b/src/js/scriptlet-filtering.js index 320f09709..aab6c8118 100644 --- a/src/js/scriptlet-filtering.js +++ b/src/js/scriptlet-filtering.js @@ -143,7 +143,15 @@ const isolatedWorldInjector = (( ) => { scriptletSlot: parts.indexOf('scriptlet-slot'), assemble: function(hostname, scriptlets) { this.parts[this.jsonSlot] = JSON.stringify({ hostname }); - return this.parts.join('').replace('function(){}', scriptlets); + const code = this.parts.join(''); + // Manually substitute noop function with scriptlet wrapper + // function, so as to not suffer instances of special + // replacement characters `$`,`\` when using String.replace() + // with in scriptlet code. + const match = /function\(\)\{\}/.exec(code); + return code.slice(0, match.index) + + scriptlets + + code.slice(match.index + match[0].length); }, }; })();