1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-15 07:22:28 +02:00

whitelisting must have precedence over strict blocking

This commit is contained in:
gorhill 2015-04-09 12:20:24 -04:00
parent f70224bb57
commit d01a73e636
2 changed files with 20 additions and 22 deletions

View File

@ -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;

View File

@ -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.