mirror of https://github.com/gorhill/uBlock.git
[mv3] Ensure filters incompatible with DNR are properly reported
This commit is contained in:
parent
0c29374a72
commit
2da9f0b03f
|
@ -197,14 +197,6 @@ const onMessage = function(request, sender, callback) {
|
|||
rule.action.redirect.transform !== undefined;
|
||||
const runtime = Date.now() - t0;
|
||||
const { ruleset } = network;
|
||||
const out = [
|
||||
`dnrRulesetFromRawLists(${JSON.stringify(listNames, null, 2)})`,
|
||||
`Run time: ${runtime} ms`,
|
||||
`Filters count: ${network.filterCount}`,
|
||||
`Accepted filter count: ${network.acceptedFilterCount}`,
|
||||
`Rejected filter count: ${network.rejectedFilterCount}`,
|
||||
`Resulting DNR rule count: ${ruleset.length}`,
|
||||
];
|
||||
const good = ruleset.filter(rule =>
|
||||
isUnsupported(rule) === false &&
|
||||
isRegex(rule) === false &&
|
||||
|
@ -212,7 +204,9 @@ const onMessage = function(request, sender, callback) {
|
|||
isCsp(rule) === false &&
|
||||
isRemoveparam(rule) === false
|
||||
);
|
||||
out.push(`+ Good filters (${good.length}): ${JSON.stringify(good, replacer, 2)}`);
|
||||
const unsupported = ruleset.filter(rule =>
|
||||
isUnsupported(rule)
|
||||
);
|
||||
const regexes = ruleset.filter(rule =>
|
||||
isUnsupported(rule) === false &&
|
||||
isRegex(rule) &&
|
||||
|
@ -220,26 +214,33 @@ const onMessage = function(request, sender, callback) {
|
|||
isCsp(rule) === false &&
|
||||
isRemoveparam(rule) === false
|
||||
);
|
||||
out.push(`+ Regex-based filters (${regexes.length}): ${JSON.stringify(regexes, replacer, 2)}`);
|
||||
const redirects = ruleset.filter(rule =>
|
||||
isUnsupported(rule) === false &&
|
||||
isRedirect(rule)
|
||||
);
|
||||
out.push(`+ 'redirect=' filters (${redirects.length}): ${JSON.stringify(redirects, replacer, 2)}`);
|
||||
const headers = ruleset.filter(rule =>
|
||||
isUnsupported(rule) === false &&
|
||||
isCsp(rule)
|
||||
);
|
||||
out.push(`+ 'csp=' filters (${headers.length}): ${JSON.stringify(headers, replacer, 2)}`);
|
||||
const removeparams = ruleset.filter(rule =>
|
||||
isUnsupported(rule) === false &&
|
||||
isRemoveparam(rule)
|
||||
);
|
||||
const out = [
|
||||
`dnrRulesetFromRawLists(${JSON.stringify(listNames, null, 2)})`,
|
||||
`Run time: ${runtime} ms`,
|
||||
`Filters count: ${network.filterCount}`,
|
||||
`Accepted filter count: ${network.acceptedFilterCount}`,
|
||||
`Rejected filter count: ${network.rejectedFilterCount}`,
|
||||
`Un-DNR-able filter count: ${unsupported.length}`,
|
||||
`Resulting DNR rule count: ${ruleset.length}`,
|
||||
];
|
||||
out.push(`+ Good filters (${good.length}): ${JSON.stringify(good, replacer, 2)}`);
|
||||
out.push(`+ Regex-based filters (${regexes.length}): ${JSON.stringify(regexes, replacer, 2)}`);
|
||||
out.push(`+ 'redirect=' filters (${redirects.length}): ${JSON.stringify(redirects, replacer, 2)}`);
|
||||
out.push(`+ 'csp=' filters (${headers.length}): ${JSON.stringify(headers, replacer, 2)}`);
|
||||
out.push(`+ 'removeparam=' filters (${removeparams.length}): ${JSON.stringify(removeparams, replacer, 2)}`);
|
||||
const bad = ruleset.filter(rule =>
|
||||
isUnsupported(rule)
|
||||
);
|
||||
out.push(`+ Unsupported filters (${bad.length}): ${JSON.stringify(bad, replacer, 2)}`);
|
||||
out.push(`+ Unsupported filters (${unsupported.length}): ${JSON.stringify(unsupported, replacer, 2)}`);
|
||||
out.push(`+ generichide exclusions (${network.generichideExclusions.length}): ${JSON.stringify(network.generichideExclusions, replacer, 2)}`);
|
||||
if ( result.specificCosmetic ) {
|
||||
out.push(`+ Cosmetic filters: ${result.specificCosmetic.size}`);
|
||||
|
|
|
@ -309,7 +309,12 @@ function addToDNR(context, list) {
|
|||
}
|
||||
|
||||
if ( parser.isFilter() === false ) { continue; }
|
||||
if ( parser.hasError() ) { continue; }
|
||||
if ( parser.hasError() ) {
|
||||
if ( parser.astError === sfp.AST_ERROR_OPTION_EXCLUDED ) {
|
||||
context.invalid.add(`Incompatible with DNR: ${line}`);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( parser.isExtendedFilter() ) {
|
||||
addExtendedToDNR(context, parser);
|
||||
|
|
|
@ -100,6 +100,7 @@ export const AST_ERROR_DOMAIN_NAME = 1 << iota++;
|
|||
export const AST_ERROR_OPTION_DUPLICATE = 1 << iota++;
|
||||
export const AST_ERROR_OPTION_UNKNOWN = 1 << iota++;
|
||||
export const AST_ERROR_OPTION_BADVALUE = 1 << iota++;
|
||||
export const AST_ERROR_OPTION_EXCLUDED = 1 << iota++;
|
||||
export const AST_ERROR_IF_TOKEN_UNKNOWN = 1 << iota++;
|
||||
export const AST_ERROR_UNTRUSTED_SOURCE = 1 << iota++;
|
||||
|
||||
|
@ -1303,6 +1304,7 @@ export class AstFilterParser {
|
|||
if ( this.badTypes.has(type) ) {
|
||||
this.addNodeFlags(NODE_FLAG_ERROR);
|
||||
this.addFlags(AST_FLAG_HAS_ERROR);
|
||||
this.astError = AST_ERROR_OPTION_EXCLUDED;
|
||||
}
|
||||
const flags = this.getNodeFlags(targetNode);
|
||||
if ( (flags & NODE_FLAG_ERROR) !== 0 ) { continue; }
|
||||
|
|
|
@ -878,8 +878,7 @@ class FilterPatternPlain {
|
|||
if ( rule.condition === undefined ) {
|
||||
rule.condition = {};
|
||||
} else if ( rule.condition.urlFilter !== undefined ) {
|
||||
rule._error = rule._error || [];
|
||||
rule._error.push(`urlFilter already defined: ${rule.condition.urlFilter}`);
|
||||
dnrAddRuleError(rule, `urlFilter already defined: ${rule.condition.urlFilter}`);
|
||||
}
|
||||
rule.condition.urlFilter = args[1];
|
||||
}
|
||||
|
@ -4474,7 +4473,7 @@ FilterContainer.prototype.dnrFromCompiled = function(op, context, ...args) {
|
|||
value: rule.__modifierValue,
|
||||
}];
|
||||
if ( rule.__modifierAction === ALLOW_REALM ) {
|
||||
dnrAddRuleError(rule, 'Unsupported modifier exception');
|
||||
dnrAddRuleError(rule, `Unsupported csp exception: ${rule.__modifierValue}`);
|
||||
}
|
||||
break;
|
||||
case 'permissions':
|
||||
|
@ -4485,7 +4484,7 @@ FilterContainer.prototype.dnrFromCompiled = function(op, context, ...args) {
|
|||
value: rule.__modifierValue.split('|').join(', '),
|
||||
}];
|
||||
if ( rule.__modifierAction === ALLOW_REALM ) {
|
||||
dnrAddRuleError(rule, 'Unsupported modifier exception');
|
||||
dnrAddRuleError(rule, `Unsupported permissions exception: ${rule.__modifierValue}`);
|
||||
}
|
||||
break;
|
||||
case 'redirect-rule': {
|
||||
|
@ -4548,7 +4547,7 @@ FilterContainer.prototype.dnrFromCompiled = function(op, context, ...args) {
|
|||
];
|
||||
}
|
||||
if ( rule.__modifierAction === ALLOW_REALM ) {
|
||||
dnrAddRuleError(rule, 'Unsupported modifier exception');
|
||||
dnrAddRuleError(rule, `Unsupported removeparam exception: ${rule.__modifierValue}`);
|
||||
}
|
||||
break;
|
||||
case 'urltransform': {
|
||||
|
|
Loading…
Reference in New Issue