1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-07 03:12:33 +01:00

[mv3] Salvage network rules with entity syntax in domain= option

It's possible to salvage network rule with entity syntax-based
entries in their `domain=` option if there exists at least one
entry which is not entity syntax-based.

For negated entries, these can be unconditionally removed
safely.
This commit is contained in:
Raymond Hill 2022-10-17 17:41:13 -04:00
parent 83b9ca5db6
commit 44812dd3c0
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -1740,11 +1740,6 @@ const FilterOriginEntityHit = class extends FilterOriginHit {
static compile(entity) { static compile(entity) {
return [ FilterOriginEntityHit.fid, entity ]; return [ FilterOriginEntityHit.fid, entity ];
} }
static dnrFromCompiled(args, rule) {
dnrAddRuleError(rule, `FilterOriginEntityHit: Entity ${args[1]} not supported`);
super.dnrFromCompiled(args, rule);
}
}; };
registerFilterClass(FilterOriginEntityHit); registerFilterClass(FilterOriginEntityHit);
@ -1759,11 +1754,6 @@ const FilterOriginEntityMiss = class extends FilterOriginMiss {
static compile(entity) { static compile(entity) {
return [ FilterOriginEntityMiss.fid, entity ]; return [ FilterOriginEntityMiss.fid, entity ];
} }
static dnrFromCompiled(args, rule) {
dnrAddRuleError(rule, `FilterOriginEntityMiss: Entity ${args[1]} not supported`);
super.dnrFromCompiled(args, rule);
}
}; };
registerFilterClass(FilterOriginEntityMiss); registerFilterClass(FilterOriginEntityMiss);
@ -4062,6 +4052,36 @@ FilterContainer.prototype.dnrFromCompiled = function(op, context, ...args) {
} }
} }
// Detect and attempt salvage of rules with entity-based hostnames.
for ( const rule of ruleset ) {
if ( rule.condition === undefined ) { continue; }
if (
Array.isArray(rule.condition.initiatorDomains) &&
rule.condition.initiatorDomains.some(hn => hn.endsWith('.*'))
) {
const domains = rule.condition.initiatorDomains.filter(
hn => hn.endsWith('.*') === false
);
if ( domains.length === 0 ) {
dnrAddRuleError(rule, `Could not salvage rule with only entity-based domain= option: ${rule.condition.initiatorDomains.join('|')}`);
} else {
rule.condition.initiatorDomains = domains;
}
}
if (
Array.isArray(rule.condition.excludedInitiatorDomains) &&
rule.condition.excludedInitiatorDomains.some(hn => hn.endsWith('.*'))
) {
const domains = rule.condition.excludedInitiatorDomains.filter(
hn => hn.endsWith('.*') === false
);
rule.condition.excludedInitiatorDomains =
domains.length !== 0
? domains
: undefined;
}
}
// Patch modifier filters // Patch modifier filters
for ( const rule of ruleset ) { for ( const rule of ruleset ) {
if ( rule.__modifierType === undefined ) { continue; } if ( rule.__modifierType === undefined ) { continue; }