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

this addresses #405

This commit is contained in:
Raymond Hill 2014-12-08 15:37:35 -02:00
parent 172f98d462
commit a85f64c562
2 changed files with 41 additions and 25 deletions

View File

@ -333,6 +333,11 @@ PageStore.prototype.reuse = function(pageURL, context) {
this.pageDomain = µb.URI.domainFromHostname(this.pageHostname) || this.pageHostname;
this.rootHostname = this.pageHostname;
this.rootDomain = this.pageDomain;
// As part of https://github.com/gorhill/uBlock/issues/405
// URL changed, force a re-evaluation of filtering switch
this.netFilteringReadTime = 0;
return this;
}
// A new page is completely reloaded from scratch, reset all.

View File

@ -47,19 +47,9 @@
}
var i = exceptions.length;
var exception;
while ( i-- ) {
exception = exceptions[i];
if ( exception.indexOf('/') !== -1 ) {
if ( exception.slice(-1) === '*' ) {
exception = exception.slice(0, -1);
if ( keyURL.slice(0, exception.length) === exception ) {
return false;
}
} else if ( keyURL === exception ) {
return false;
}
} else if ( keyHostname.slice(-exception.length) === exception ) {
if ( this.matchWhitelistException(keyURL, keyHostname, exceptions[i]) ) {
// console.log('"%s" matche url "%s"', exceptions[i], keyURL);
return false;
}
}
@ -105,21 +95,10 @@
return true;
}
// Remove from exception list
// Remove from exception list whatever causes current URL to be whitelisted
var i = exceptions.length;
var exception;
while ( i-- ) {
exception = exceptions[i];
if ( exception.indexOf('/') !== -1 ) {
if ( exception.slice(-1) === '*' ) {
exception = exception.slice(0, -1);
if ( keyURL.slice(0, exception.length) === exception ) {
exceptions.splice(i, 1);
}
} else if ( keyURL === exception ) {
exceptions.splice(i, 1);
}
} else if ( keyHostname.slice(-exception.length) === exception ) {
if ( this.matchWhitelistException(keyURL, keyHostname, exceptions[i]) ) {
exceptions.splice(i, 1);
}
}
@ -132,6 +111,38 @@
/******************************************************************************/
// https://github.com/gorhill/uBlock/issues/405
// Be more flexible with whitelist syntax
// TODO: Need to harden it against edge cases, like when an asterisk is used in
// place of protocol.
µBlock.matchWhitelistException = function(url, hostname, exception) {
// Exception is a plain hostname
if ( exception.indexOf('/') === -1 ) {
return hostname.slice(-exception.length) === exception;
}
// Match URL exactly
if ( exception.indexOf('*') === -1 ) {
return url === exception;
}
// Regex escape code inspired from:
// "Is there a RegExp.escape function in Javascript?"
// http://stackoverflow.com/a/3561711
var reStr = exception.replace(this.whitelistExceptionEscape, '\\$&')
.replace(this.whitelistExceptionEscapeAsterisk, '.*');
var re = new RegExp(reStr);
return re.test(url);
};
// Any special regexp char will be escaped
µBlock.whitelistExceptionEscape = /[-\/\\^$+?.()|[\]{}]/g;
// All `*` will be expanded into `.*`
µBlock.whitelistExceptionEscapeAsterisk = /\*/g;
/******************************************************************************/
// For now we will use the net exception list
µBlock.getCosmeticFilteringSwitch = function(url, domain) {