Skip to content

Commit 56e1d92

Browse files
committed
Fix/improve scriptlets
Related issue: - uBlockOrigin/uBlock-issues#2678 - uBlockOrigin/uAssets#18278
1 parent 996bf09 commit 56e1d92

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

assets/resources/scriptlets.js

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,23 +1049,11 @@ function evaldataPrune(
10491049
) {
10501050
self.eval = new Proxy(self.eval, {
10511051
apply(target, thisArg, args) {
1052-
let dataToEval = `${args[0]}`;
1053-
const match = /^\s*\(\s*(\{.+\})\s*\)\s*$/s.exec(dataToEval);
1054-
if ( match !== null ) {
1055-
dataToEval = match[1];
1052+
let data = Reflect.apply(target, thisArg, args);
1053+
if ( typeof data === 'object' ) {
1054+
data = objectPrune(data, rawPrunePaths, rawNeedlePaths);
10561055
}
1057-
let data;
1058-
try {
1059-
data = JSON.parse(dataToEval);
1060-
if ( typeof data === 'object' ) {
1061-
let after = JSON.stringify(
1062-
objectPrune(data, rawPrunePaths, rawNeedlePaths)
1063-
);
1064-
args[0] = `(${after})`;
1065-
}
1066-
} catch(ex) {
1067-
}
1068-
return Reflect.apply(target, thisArg, args);
1056+
return data;
10691057
}
10701058
});
10711059
}
@@ -2332,7 +2320,7 @@ function hrefSanitizer(
23322320
};
23332321
const extractText = (elem, source) => {
23342322
if ( /^\[.*\]$/.test(source) ) {
2335-
return elem.getAttribute(source.slice(1,-1).trim()) || '';
2323+
source = elem.getAttribute(source.slice(1,-1).trim()) || '';
23362324
}
23372325
if ( source !== 'text' ) { return ''; }
23382326
const text = elem.textContent

0 commit comments

Comments
 (0)