From 6891037758354c809953a549017f654437ed38c7 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sat, 17 Aug 2024 11:00:42 -0400 Subject: [PATCH] [mv3] Fix exception filters not overriding redirect filters Related issue: https://github.com/uBlockOrigin/uBOL-home/issues/185 --- src/js/static-net-filtering.js | 37 +++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/js/static-net-filtering.js b/src/js/static-net-filtering.js index 96aaff79e..84d04478d 100644 --- a/src/js/static-net-filtering.js +++ b/src/js/static-net-filtering.js @@ -752,7 +752,7 @@ class FilterImportant { } static dnrFromCompiled(args, rule) { - rule.priority = (rule.priority || 1) + 10; + rule.priority = (rule.priority || 1) + 30; } 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([ - [ BLOCK_REALM, 'block' ], - [ ALLOW_REALM, 'allow' ], - [ REDIRECT_REALM, 'redirect' ], - [ REMOVEPARAM_REALM, 'removeparam' ], - [ CSP_REALM, 'csp' ], - [ PERMISSIONS_REALM, 'permissions' ], - [ URLTRANSFORM_REALM, 'uritransform' ], + [ BLOCK_REALM, { type: 'block', priority: 0 } ], + [ ALLOW_REALM, { type: 'allow', priority: 20 } ], + [ REDIRECT_REALM, { type: 'redirect', priority: 1 } ], + [ REMOVEPARAM_REALM, { type: 'removeparam', priority: 0 } ], + [ CSP_REALM, { type: 'csp', priority: 0 } ], + [ PERMISSIONS_REALM, { type: 'permissions', priority: 0 } ], + [ URLTRANSFORM_REALM, { type: 'uritransform', priority: 0 } ], ]); const partyness = new Map([ [ ANYPARTY_REALM, '' ], @@ -4342,7 +4350,7 @@ StaticNetFilteringEngine.prototype.dnrFromCompiled = function(op, context, ...ar 'other', ]); const ruleset = []; - for ( const [ realmBits, realmName ] of realms ) { + for ( const [ realmBits, realmDetails ] of realms ) { for ( const [ partyBits, partyName ] of partyness ) { for ( const typeName in typeNameToTypeValue ) { 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 rule of rules ) { 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 !== '' ) { rule.condition = rule.condition || {}; rule.condition.domainType = partyName; @@ -4449,12 +4460,11 @@ StaticNetFilteringEngine.prototype.dnrFromCompiled = function(op, context, ...ar } break; case 'redirect-rule': { - let priority = rule.priority || 1; let token = rule.__modifierValue; if ( token !== '' ) { const match = /:(\d+)$/.exec(token); 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); } } @@ -4466,10 +4476,9 @@ StaticNetFilteringEngine.prototype.dnrFromCompiled = function(op, context, ...ar const extensionPath = resource || token; rule.action.type = 'redirect'; rule.action.redirect = { extensionPath }; - rule.priority = priority + 1; } else { rule.action.type = 'block'; - rule.priority = priority + 2; + rule.priority += 10; } break; }