Skip to content

Commit

Permalink
Add support for "remove all properties" in json-prune scriptlet
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Apr 6, 2021
1 parent 9a94ba0 commit d338e4c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions assets/resources/scriptlets.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@
// When no "prune paths" argument is provided, the scriptlet is
// used for logging purpose and the "needle paths" argument is
// used to filter logging output.
//
// https://github.com/uBlockOrigin/uBlock-issues/issues/1545
// - Add support for "remove everything if needle matches" case
//
(function() {
const rawPrunePaths = '{{1}}';
const rawNeedlePaths = '{{2}}';
Expand Down Expand Up @@ -401,9 +405,15 @@
}
const pos = chain.indexOf('.');
if ( pos === -1 ) {
const found = owner.hasOwnProperty(chain);
if ( found === false ) { return false; }
if ( prune ) {
if ( prune === false ) {
return owner.hasOwnProperty(chain);
}
if ( chain === '*' ) {
for ( const key in owner ) {
if ( owner.hasOwnProperty(key) === false ) { continue; }
delete owner[key];
}
} else if ( owner.hasOwnProperty(chain) ) {
delete owner[chain];
}
return true;
Expand Down

0 comments on commit d338e4c

Please sign in to comment.