From d01a73e6365af5475856148d00b4e25771ae4a4f Mon Sep 17 00:00:00 2001 From: gorhill Date: Thu, 9 Apr 2015 12:20:24 -0400 Subject: [PATCH] whitelisting must have precedence over strict blocking --- src/js/hnswitches.js | 25 ++++++++----------------- src/js/traffic.js | 17 ++++++++++++----- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/js/hnswitches.js b/src/js/hnswitches.js index 6c0eea167..0f0d7d3f1 100644 --- a/src/js/hnswitches.js +++ b/src/js/hnswitches.js @@ -51,13 +51,15 @@ var fromLegacySwitchNames = { }; var switchStateToNameMap = { - '1': 'true', - '2': 'false' + '1': 'on', + '2': 'off' }; var nameToSwitchStateMap = { 'true': 1, - 'false': 2 + 'false': 2, + 'on': 1, + 'off': 2 }; /******************************************************************************/ @@ -160,10 +162,10 @@ HnSwitches.prototype.toggleOneZ = function(switchName, hostname, newState) { HnSwitches.prototype.toggleBranchZ = function(switchName, targetHostname, newState) { var changed = this.toggleOneZ(switchName, targetHostname, newState); - var targetLen = targetHostname.length; - var hostnames = []; + // Turn off all descendant switches, they will inherit the state of the + // branch's origin. for ( var hostname in this.switches ) { if ( this.switches.hasOwnProperty(hostname) === false ) { continue; @@ -180,18 +182,7 @@ HnSwitches.prototype.toggleBranchZ = function(switchName, targetHostname, newSta if ( hostname.charAt(hostname.length - targetLen - 1) !== '.' ) { continue; } - hostnames.push(hostname); - } - - // Decreasing length order so that all switch states are inherited from - // targetHostname. - hostnames.sort(function(a, b) { - return b.length - a.length; - }); - - var i = hostnames.length; - while ( i-- ) { - changed = this.toggleOneZ(switchName, hostnames[i], newState) || changed; + changed = this.toggle(switchName, hostname, 0) || changed; } return changed; diff --git a/src/js/traffic.js b/src/js/traffic.js index 74919abac..33fc718f7 100644 --- a/src/js/traffic.js +++ b/src/js/traffic.js @@ -153,19 +153,26 @@ var onBeforeRootFrameRequest = function(details) { var result = ''; + // If the site is whitelisted, disregard strict blocking + if ( µb.getNetFilteringSwitch(requestURL) === false ) { + result = 'ua:whitelisted'; + } + // Permanently unrestricted? if ( result === '' && µb.hnSwitches.evaluateZ('no-strict-blocking', requestHostname) ) { - result = 'ua:no-strict-blocking true'; + result = 'ua:no-strict-blocking on'; } // Temporarily whitelisted? - result = isTemporarilyWhitelisted(result, requestHostname); - if ( result.charAt(1) === 'a' ) { - return; + if ( result === '' ) { + result = isTemporarilyWhitelisted(result, requestHostname); + if ( result.charAt(1) === 'a' ) { + result = 'ua:no-strict-blocking on(temporary)'; + } } // Filtering - if ( result === '' && µb.getNetFilteringSwitch(requestURL) ) { + if ( result === '' ) { result = µb.staticNetFilteringEngine.matchString(context); // https://github.com/chrisaljoudi/uBlock/issues/1128 // Do not block if the match begins after the hostname.