From c956b933696b9559720f3f9517fd895696575fa0 Mon Sep 17 00:00:00 2001 From: gorhill Date: Mon, 3 Oct 2016 23:41:23 -0400 Subject: [PATCH] fix #1669 --- src/js/background.js | 4 ++-- src/js/static-net-filtering.js | 32 +++++++++++++++++++++----------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/js/background.js b/src/js/background.js index c63d680b3..69ca57b92 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -94,8 +94,8 @@ return { // read-only systemSettings: { - compiledMagic: 'ryegxvatkfxe', - selfieMagic: 'ryegxvatkfxe' + compiledMagic: 'lbmqiweqbvha', + selfieMagic: 'lbmqiweqbvha' }, restoreBackupSettings: { diff --git a/src/js/static-net-filtering.js b/src/js/static-net-filtering.js index 42240af5a..c361161a9 100644 --- a/src/js/static-net-filtering.js +++ b/src/js/static-net-filtering.js @@ -858,14 +858,15 @@ FilterGenericHostname.fromSelfie = function(s) { // whether the start of the match falls within the hostname part of the // URL. -var FilterGenericHnAnchored = function(s) { +var FilterGenericHnAnchored = function(s, anchor) { this.s = s; + this.anchor = anchor; this.re = null; }; FilterGenericHnAnchored.prototype.match = function(url) { if ( this.re === null ) { - this.re = strToRegex('||' + this.s, 0); + this.re = strToRegex('||' + this.s, this.anchor); } var matchStart = url.search(this.re); return matchStart !== -1 && isHnAnchored(url, matchStart); @@ -877,21 +878,22 @@ FilterGenericHnAnchored.prototype.rtfid = '||_'; FilterGenericHnAnchored.prototype.toSelfie = FilterGenericHnAnchored.prototype.rtCompile = function() { - return this.s; + return this.s + '\t' + this.anchor; }; FilterGenericHnAnchored.compile = function(details) { - return details.f; + return details.f + '\t' + details.anchor; }; FilterGenericHnAnchored.fromSelfie = function(s) { - return new FilterGenericHnAnchored(s); + var pos = s.indexOf('\t'); + return new FilterGenericHnAnchored(s.slice(0, pos), parseInt(s.slice(pos + 1), 10)); }; /******************************************************************************/ -var FilterGenericHnAnchoredHostname = function(s, domainOpt) { - FilterGenericHnAnchored.call(this, s); +var FilterGenericHnAnchoredHostname = function(s, anchor, domainOpt) { + FilterGenericHnAnchored.call(this, s, anchor); this.domainOpt = domainOpt; this.hostnameTest = hostnameTestPicker(this); }; @@ -909,16 +911,16 @@ FilterGenericHnAnchoredHostname.prototype.rtfid = '||_h'; FilterGenericHnAnchoredHostname.prototype.toSelfie = FilterGenericHnAnchoredHostname.prototype.rtCompile = function() { - return this.s + '\t' + this.domainOpt; + return this.s + '\t' + this.anchor + '\t' + this.domainOpt; }; FilterGenericHnAnchoredHostname.compile = function(details) { - return details.f + '\t' + details.domainOpt; + return details.f + '\t' + details.anchor + '\t' + details.domainOpt; }; FilterGenericHnAnchoredHostname.fromSelfie = function(s) { - var pos = s.indexOf('\t'); - return new FilterGenericHnAnchoredHostname(s.slice(0, pos), s.slice(pos + 1)); + var fields = s.split('\t'); + return new FilterGenericHnAnchoredHostname(fields[0], parseInt(fields[1], 10), fields[2]); }; /******************************************************************************/ @@ -1749,6 +1751,10 @@ FilterContainer.prototype.getFilterClass = function(details) { return FilterPlainLeftAnchoredHostname; } if ( details.anchor > 0 ) { + // https://github.com/gorhill/uBlock/issues/1669 + if ( details.hostnameAnchored ) { + return FilterGenericHnAnchoredHostname; + } return FilterPlainRightAnchoredHostname; } if ( details.hostnameAnchored ) { @@ -1776,6 +1782,10 @@ FilterContainer.prototype.getFilterClass = function(details) { return FilterPlainLeftAnchored; } if ( details.anchor > 0 ) { + // https://github.com/gorhill/uBlock/issues/1669 + if ( details.hostnameAnchored ) { + return FilterGenericHnAnchored; + } return FilterPlainRightAnchored; } if ( details.hostnameAnchored ) {