1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-05 11:37:01 +02:00

Add support for "remove all properties" in json-prune scriptlet

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1545
This commit is contained in:
Raymond Hill 2021-04-06 10:12:34 -04:00
parent 9a94ba0a22
commit d338e4c4b6
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -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}}';
@ -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;