From ea15cef52456bfc8594943be133a6d25574b17ba Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 26 May 2023 13:18:20 -0400 Subject: [PATCH] [mv3] Also log salvaged rules using entity-based domains Some filters with entity-based domain option can be salvaged when there are non-entity-based domain option, but since we are throwing away the entity-based entries, we are only partially converting to DNR. This commit will log a warning about this in log.txt. Before this commit, only non-salvageable filters were logged. --- platform/mv3/make-rulesets.js | 6 ++++++ src/js/static-net-filtering.js | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/platform/mv3/make-rulesets.js b/platform/mv3/make-rulesets.js index ccc2f1b5c..2368ecde5 100644 --- a/platform/mv3/make-rulesets.js +++ b/platform/mv3/make-rulesets.js @@ -267,6 +267,12 @@ async function processNetworkFilters(assetDetails, network) { const plainGood = rules.filter(rule => isGood(rule) && isRegex(rule) === false); log(`\tPlain good: ${plainGood.length}`); + log(plainGood + .filter(rule => Array.isArray(rule._warning)) + .map(rule => rule._warning.map(v => `\t\t${v}`)) + .join('\n'), + true + ); const regexes = rules.filter(rule => isGood(rule) && isRegex(rule)); log(`\tMaybe good (regexes): ${regexes.length}`); diff --git a/src/js/static-net-filtering.js b/src/js/static-net-filtering.js index 6dd29c969..bd912f607 100644 --- a/src/js/static-net-filtering.js +++ b/src/js/static-net-filtering.js @@ -673,6 +673,11 @@ const dnrAddRuleError = (rule, msg) => { rule._error.push(msg); }; +const dnrAddRuleWarning = (rule, msg) => { + rule._warning = rule._warning || []; + rule._warning.push(msg); +}; + /******************************************************************************* Filter classes @@ -4385,8 +4390,9 @@ FilterContainer.prototype.dnrFromCompiled = function(op, context, ...args) { hn => hn.endsWith('.*') === false ); if ( domains.length === 0 ) { - dnrAddRuleError(rule, `Could not salvage rule with only entity-based domain= option: ${rule.condition.initiatorDomains.join('|')}`); + dnrAddRuleError(rule, `Can't salvage rule with only entity-based domain= option: ${rule.condition.initiatorDomains.join('|')}`); } else { + dnrAddRuleWarning(rule, `Salvaged rule by ignoring ${rule.condition.initiatorDomains.length - domains.length} entity-based domain= option: ${rule.condition.initiatorDomains.join('|')}`); rule.condition.initiatorDomains = domains; } }