[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.
This commit is contained in:
Raymond Hill 2023-05-26 13:18:20 -04:00
parent 86ba04dd68
commit ea15cef524
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 13 additions and 1 deletions

View File

@ -267,6 +267,12 @@ async function processNetworkFilters(assetDetails, network) {
const plainGood = rules.filter(rule => isGood(rule) && isRegex(rule) === false); const plainGood = rules.filter(rule => isGood(rule) && isRegex(rule) === false);
log(`\tPlain good: ${plainGood.length}`); 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)); const regexes = rules.filter(rule => isGood(rule) && isRegex(rule));
log(`\tMaybe good (regexes): ${regexes.length}`); log(`\tMaybe good (regexes): ${regexes.length}`);

View File

@ -673,6 +673,11 @@ const dnrAddRuleError = (rule, msg) => {
rule._error.push(msg); rule._error.push(msg);
}; };
const dnrAddRuleWarning = (rule, msg) => {
rule._warning = rule._warning || [];
rule._warning.push(msg);
};
/******************************************************************************* /*******************************************************************************
Filter classes Filter classes
@ -4385,8 +4390,9 @@ FilterContainer.prototype.dnrFromCompiled = function(op, context, ...args) {
hn => hn.endsWith('.*') === false hn => hn.endsWith('.*') === false
); );
if ( domains.length === 0 ) { 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 { } 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; rule.condition.initiatorDomains = domains;
} }
} }