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:
parent
172f98d462
commit
a85f64c562
@ -333,6 +333,11 @@ PageStore.prototype.reuse = function(pageURL, context) {
|
|||||||
this.pageDomain = µb.URI.domainFromHostname(this.pageHostname) || this.pageHostname;
|
this.pageDomain = µb.URI.domainFromHostname(this.pageHostname) || this.pageHostname;
|
||||||
this.rootHostname = this.pageHostname;
|
this.rootHostname = this.pageHostname;
|
||||||
this.rootDomain = this.pageDomain;
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
// A new page is completely reloaded from scratch, reset all.
|
// A new page is completely reloaded from scratch, reset all.
|
||||||
|
@ -47,19 +47,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
var i = exceptions.length;
|
var i = exceptions.length;
|
||||||
var exception;
|
|
||||||
while ( i-- ) {
|
while ( i-- ) {
|
||||||
exception = exceptions[i];
|
if ( this.matchWhitelistException(keyURL, keyHostname, exceptions[i]) ) {
|
||||||
if ( exception.indexOf('/') !== -1 ) {
|
// console.log('"%s" matche url "%s"', exceptions[i], keyURL);
|
||||||
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 ) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -105,21 +95,10 @@
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove from exception list
|
// Remove from exception list whatever causes current URL to be whitelisted
|
||||||
var i = exceptions.length;
|
var i = exceptions.length;
|
||||||
var exception;
|
|
||||||
while ( i-- ) {
|
while ( i-- ) {
|
||||||
exception = exceptions[i];
|
if ( this.matchWhitelistException(keyURL, keyHostname, 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 ) {
|
|
||||||
exceptions.splice(i, 1);
|
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
|
// For now we will use the net exception list
|
||||||
|
|
||||||
µBlock.getCosmeticFilteringSwitch = function(url, domain) {
|
µBlock.getCosmeticFilteringSwitch = function(url, domain) {
|
||||||
|
Loading…
Reference in New Issue
Block a user