1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-16 23:42:39 +01:00

[mv3] Fix exception filters not overriding redirect filters

Related issue:
https://github.com/uBlockOrigin/uBOL-home/issues/185
This commit is contained in:
Raymond Hill 2024-08-17 11:00:42 -04:00
parent e73eb23c90
commit 6891037758
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -752,7 +752,7 @@ class FilterImportant {
} }
static dnrFromCompiled(args, rule) { static dnrFromCompiled(args, rule) {
rule.priority = (rule.priority || 1) + 10; rule.priority = (rule.priority || 1) + 30;
} }
static keyFromArgs() { static keyFromArgs() {
@ -4312,14 +4312,22 @@ StaticNetFilteringEngine.prototype.dnrFromCompiled = function(op, context, ...ar
} }
} }
// Priority:
// Block: 0 (default priority)
// Redirect: 1-9
// Excepted redirect: 11-19
// Allow: 20
// Block important: 30
// Redirect important: 31-39
const realms = new Map([ const realms = new Map([
[ BLOCK_REALM, 'block' ], [ BLOCK_REALM, { type: 'block', priority: 0 } ],
[ ALLOW_REALM, 'allow' ], [ ALLOW_REALM, { type: 'allow', priority: 20 } ],
[ REDIRECT_REALM, 'redirect' ], [ REDIRECT_REALM, { type: 'redirect', priority: 1 } ],
[ REMOVEPARAM_REALM, 'removeparam' ], [ REMOVEPARAM_REALM, { type: 'removeparam', priority: 0 } ],
[ CSP_REALM, 'csp' ], [ CSP_REALM, { type: 'csp', priority: 0 } ],
[ PERMISSIONS_REALM, 'permissions' ], [ PERMISSIONS_REALM, { type: 'permissions', priority: 0 } ],
[ URLTRANSFORM_REALM, 'uritransform' ], [ URLTRANSFORM_REALM, { type: 'uritransform', priority: 0 } ],
]); ]);
const partyness = new Map([ const partyness = new Map([
[ ANYPARTY_REALM, '' ], [ ANYPARTY_REALM, '' ],
@ -4342,7 +4350,7 @@ StaticNetFilteringEngine.prototype.dnrFromCompiled = function(op, context, ...ar
'other', 'other',
]); ]);
const ruleset = []; const ruleset = [];
for ( const [ realmBits, realmName ] of realms ) { for ( const [ realmBits, realmDetails ] of realms ) {
for ( const [ partyBits, partyName ] of partyness ) { for ( const [ partyBits, partyName ] of partyness ) {
for ( const typeName in typeNameToTypeValue ) { for ( const typeName in typeNameToTypeValue ) {
if ( types.has(typeName) === false ) { continue; } if ( types.has(typeName) === false ) { continue; }
@ -4353,7 +4361,10 @@ StaticNetFilteringEngine.prototype.dnrFromCompiled = function(op, context, ...ar
for ( const rules of bucket.values() ) { for ( const rules of bucket.values() ) {
for ( const rule of rules ) { for ( const rule of rules ) {
rule.action = rule.action || {}; rule.action = rule.action || {};
rule.action.type = realmName; rule.action.type = realmDetails.type;
if ( realmDetails.priority !== 0 ) {
rule.priority = (rule.priority || 0) + realmDetails.priority;
}
if ( partyName !== '' ) { if ( partyName !== '' ) {
rule.condition = rule.condition || {}; rule.condition = rule.condition || {};
rule.condition.domainType = partyName; rule.condition.domainType = partyName;
@ -4449,12 +4460,11 @@ StaticNetFilteringEngine.prototype.dnrFromCompiled = function(op, context, ...ar
} }
break; break;
case 'redirect-rule': { case 'redirect-rule': {
let priority = rule.priority || 1;
let token = rule.__modifierValue; let token = rule.__modifierValue;
if ( token !== '' ) { if ( token !== '' ) {
const match = /:(\d+)$/.exec(token); const match = /:(\d+)$/.exec(token);
if ( match !== null ) { if ( match !== null ) {
priority += parseInt(match[1], 10); rule.priority = Math.min(rule.priority + parseInt(match[1], 10), 9);
token = token.slice(0, match.index); token = token.slice(0, match.index);
} }
} }
@ -4466,10 +4476,9 @@ StaticNetFilteringEngine.prototype.dnrFromCompiled = function(op, context, ...ar
const extensionPath = resource || token; const extensionPath = resource || token;
rule.action.type = 'redirect'; rule.action.type = 'redirect';
rule.action.redirect = { extensionPath }; rule.action.redirect = { extensionPath };
rule.priority = priority + 1;
} else { } else {
rule.action.type = 'block'; rule.action.type = 'block';
rule.priority = priority + 2; rule.priority += 10;
} }
break; break;
} }