From 318f2bf093cedaba25721763fa31704fe90b6d8e Mon Sep 17 00:00:00 2001 From: gorhill Date: Mon, 27 Apr 2015 15:09:19 -0400 Subject: [PATCH] this fixes #142 --- src/js/background.js | 2 +- src/js/static-net-filtering.js | 83 ++++++++++++++++++++++++++-------- 2 files changed, 65 insertions(+), 20 deletions(-) diff --git a/src/js/background.js b/src/js/background.js index 3d335ee88..262823881 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -90,7 +90,7 @@ return { // read-only systemSettings: { - compiledMagic: 'cjrthpvolupa', + compiledMagic: 'akjbdyreyxgm', selfieMagic: 'spqmeuaftfra' }, diff --git a/src/js/static-net-filtering.js b/src/js/static-net-filtering.js index f8d521115..0b7e22a36 100644 --- a/src/js/static-net-filtering.js +++ b/src/js/static-net-filtering.js @@ -572,6 +572,47 @@ FilterPlainHnAnchored.fromSelfie = function(s) { /******************************************************************************/ +// https://github.com/gorhill/uBlock/issues/142 + +var FilterPlainHnAnchoredHostname = function(s, hostname) { + this.s = s; + this.hostname = hostname; +}; + +FilterPlainHnAnchoredHostname.prototype.match = function(url, tokenBeg) { + if ( pageHostnameRegister.slice(-this.hostname.length) !== this.hostname ) { + return false; + } + if ( url.substr(tokenBeg, this.s.length) !== this.s ) { + return false; + } + // Valid only if hostname-valid characters to the left of token + var pos = url.indexOf('://'); + return pos !== -1 && + reURLPostHostnameAnchors.test(url.slice(pos + 3, tokenBeg)) === false; +}; + +FilterPlainHnAnchoredHostname.fid = FilterPlainHnAnchoredHostname.prototype.fid = '||ah'; + +FilterPlainHnAnchoredHostname.prototype.toString = function() { + return '||' + this.s; +}; + +FilterPlainHnAnchoredHostname.prototype.toSelfie = function() { + return this.s + '\t' + this.hostname; +}; + +FilterPlainHnAnchoredHostname.compile = function(details, hostname) { + return details.f + '\t' + hostname; +}; + +FilterPlainHnAnchoredHostname.fromSelfie = function(s) { + var pos = s.indexOf('\t'); + return new FilterPlainHnAnchoredHostname(s.slice(0, pos), s.slice(pos + 1)); +}; + +/******************************************************************************/ + // Generic filter var FilterGeneric = function(s, anchor) { @@ -1143,6 +1184,9 @@ var getHostnameBasedFilterClass = function(details) { if ( details.anchor > 0 ) { return FilterPlainRightAnchoredHostname; } + if ( details.hostnameAnchored ) { + return FilterPlainHnAnchoredHostname; + } if ( details.tokenBeg === 0 ) { return FilterPlainPrefix0Hostname; } @@ -1574,25 +1618,26 @@ FilterContainer.prototype.freeze = function() { /******************************************************************************/ FilterContainer.prototype.factories = { - '[]': FilterBucket, - 'a': FilterPlain, - 'ah': FilterPlainHostname, - '0a': FilterPlainPrefix0, - '0ah': FilterPlainPrefix0Hostname, - '1a': FilterPlainPrefix1, - '1ah': FilterPlainPrefix1Hostname, - '|a': FilterPlainLeftAnchored, - '|ah': FilterPlainLeftAnchoredHostname, - 'a|': FilterPlainRightAnchored, - 'a|h': FilterPlainRightAnchoredHostname, - '||a': FilterPlainHnAnchored, - '//': FilterRegex, - '//h': FilterRegexHostname, - '{h}': FilterHostnameDict, - '_': FilterGeneric, - '_h': FilterGenericHostname, - '||_': FilterGenericHnAnchored, - '||_h': FilterGenericHnAnchoredHostname + '[]': FilterBucket, + 'a': FilterPlain, + 'ah': FilterPlainHostname, + '0a': FilterPlainPrefix0, + '0ah': FilterPlainPrefix0Hostname, + '1a': FilterPlainPrefix1, + '1ah': FilterPlainPrefix1Hostname, + '|a': FilterPlainLeftAnchored, + '|ah': FilterPlainLeftAnchoredHostname, + 'a|': FilterPlainRightAnchored, + 'a|h': FilterPlainRightAnchoredHostname, + '||a': FilterPlainHnAnchored, + '||ah': FilterPlainHnAnchoredHostname, + '//': FilterRegex, + '//h': FilterRegexHostname, + '{h}': FilterHostnameDict, + '_': FilterGeneric, + '_h': FilterGenericHostname, + '||_': FilterGenericHnAnchored, + '||_h': FilterGenericHnAnchoredHostname }; /******************************************************************************/