1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-02 17:19:38 +02:00

Fix assembling of scriptlets for isolated world

This commit is contained in:
Raymond Hill 2023-06-01 08:48:27 -04:00
parent 9b682dff03
commit 40141e2dfc
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -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);
},
};
})();