From d338e4c4b6caf339873a60c9d48fde58e9a495ce Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 6 Apr 2021 10:12:34 -0400 Subject: [PATCH] Add support for "remove all properties" in json-prune scriptlet Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/1545 --- assets/resources/scriptlets.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/assets/resources/scriptlets.js b/assets/resources/scriptlets.js index bd7a512c8..cc630a15c 100644 --- a/assets/resources/scriptlets.js +++ b/assets/resources/scriptlets.js @@ -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;