From 56e1d92dbd65e6168620053b1fec4c21c03d664e Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 30 May 2023 08:38:35 -0400 Subject: [PATCH] Fix/improve scriptlets Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/2678 - https://github.com/uBlockOrigin/uAssets/issues/18278 --- assets/resources/scriptlets.js | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/assets/resources/scriptlets.js b/assets/resources/scriptlets.js index 2081017c9..3e3597db7 100644 --- a/assets/resources/scriptlets.js +++ b/assets/resources/scriptlets.js @@ -1049,23 +1049,11 @@ function evaldataPrune( ) { self.eval = new Proxy(self.eval, { apply(target, thisArg, args) { - let dataToEval = `${args[0]}`; - const match = /^\s*\(\s*(\{.+\})\s*\)\s*$/s.exec(dataToEval); - if ( match !== null ) { - dataToEval = match[1]; + let data = Reflect.apply(target, thisArg, args); + if ( typeof data === 'object' ) { + data = objectPrune(data, rawPrunePaths, rawNeedlePaths); } - let data; - try { - data = JSON.parse(dataToEval); - if ( typeof data === 'object' ) { - let after = JSON.stringify( - objectPrune(data, rawPrunePaths, rawNeedlePaths) - ); - args[0] = `(${after})`; - } - } catch(ex) { - } - return Reflect.apply(target, thisArg, args); + return data; } }); } @@ -2332,7 +2320,7 @@ function hrefSanitizer( }; const extractText = (elem, source) => { if ( /^\[.*\]$/.test(source) ) { - return elem.getAttribute(source.slice(1,-1).trim()) || ''; + source = elem.getAttribute(source.slice(1,-1).trim()) || ''; } if ( source !== 'text' ) { return ''; } const text = elem.textContent