Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d338e4c

Browse files
committed
Add support for "remove all properties" in json-prune scriptlet
Related issue: - uBlockOrigin/uBlock-issues#1545
1 parent 9a94ba0 commit d338e4c

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

assets/resources/scriptlets.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,10 @@
367367
// When no "prune paths" argument is provided, the scriptlet is
368368
// used for logging purpose and the "needle paths" argument is
369369
// used to filter logging output.
370+
//
371+
// https://github.com/uBlockOrigin/uBlock-issues/issues/1545
372+
// - Add support for "remove everything if needle matches" case
373+
//
370374
(function() {
371375
const rawPrunePaths = '{{1}}';
372376
const rawNeedlePaths = '{{2}}';
@@ -401,9 +405,15 @@
401405
}
402406
const pos = chain.indexOf('.');
403407
if ( pos === -1 ) {
404-
const found = owner.hasOwnProperty(chain);
405-
if ( found === false ) { return false; }
406-
if ( prune ) {
408+
if ( prune === false ) {
409+
return owner.hasOwnProperty(chain);
410+
}
411+
if ( chain === '*' ) {
412+
for ( const key in owner ) {
413+
if ( owner.hasOwnProperty(key) === false ) { continue; }
414+
delete owner[key];
415+
}
416+
} else if ( owner.hasOwnProperty(chain) ) {
407417
delete owner[chain];
408418
}
409419
return true;

0 commit comments

Comments
 (0)