mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-10 09:07:54 +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:
parent
83b9ca5db6
commit
44812dd3c0
1 changed files with 30 additions and 10 deletions
|
@ -1740,11 +1740,6 @@ const FilterOriginEntityHit = class extends FilterOriginHit {
|
|||
static compile(entity) {
|
||||
return [ FilterOriginEntityHit.fid, entity ];
|
||||
}
|
||||
|
||||
static dnrFromCompiled(args, rule) {
|
||||
dnrAddRuleError(rule, `FilterOriginEntityHit: Entity ${args[1]} not supported`);
|
||||
super.dnrFromCompiled(args, rule);
|
||||
}
|
||||
};
|
||||
|
||||
registerFilterClass(FilterOriginEntityHit);
|
||||
|
@ -1759,11 +1754,6 @@ const FilterOriginEntityMiss = class extends FilterOriginMiss {
|
|||
static compile(entity) {
|
||||
return [ FilterOriginEntityMiss.fid, entity ];
|
||||
}
|
||||
|
||||
static dnrFromCompiled(args, rule) {
|
||||
dnrAddRuleError(rule, `FilterOriginEntityMiss: Entity ${args[1]} not supported`);
|
||||
super.dnrFromCompiled(args, rule);
|
||||
}
|
||||
};
|
||||
|
||||
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
|
||||
for ( const rule of ruleset ) {
|
||||
if ( rule.__modifierType === undefined ) { continue; }
|
||||
|
|
Loading…
Reference in a new issue