Skip to content

Commit

Permalink
properly fix gorhill#2938
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Aug 31, 2017
1 parent 5cc7a3a commit 8b4b1fa
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/js/static-net-filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,11 @@ var rawToRegexStr = function(s, anchor) {
.replace(me.escape3, '')
.replace(me.escape4, '[^ ]*?');
if ( anchor & 0x4 ) {
reStr = rawToRegexStr.reTextHostnameAnchor + reStr;
reStr = (
reStr.startsWith('\\.') ?
rawToRegexStr.reTextHostnameAnchor2 :
rawToRegexStr.reTextHostnameAnchor1
) + reStr;
} else if ( anchor & 0x2 ) {
reStr = '^' + reStr;
}
Expand All @@ -213,7 +217,8 @@ rawToRegexStr.escape1 = /[.+?${}()|[\]\\]/g;
rawToRegexStr.escape2 = /\^/g;
rawToRegexStr.escape3 = /^\*|\*$/g;
rawToRegexStr.escape4 = /\*/g;
rawToRegexStr.reTextHostnameAnchor = '^[a-z-]+://(?:[^/?#]+\\.?)?';
rawToRegexStr.reTextHostnameAnchor1 = '^[a-z-]+://(?:[^/?#]+\\.)?';
rawToRegexStr.reTextHostnameAnchor2 = '^[a-z-]+://(?:[^/?#]+)?';

var filterFingerprinter = µb.CompiledLineWriter.fingerprint;

Expand Down Expand Up @@ -450,7 +455,7 @@ FilterPlainHostname.prototype.match = function() {
FilterPlainHostname.prototype.logData = function() {
return {
raw: '||' + this.s + '^',
regex: rawToRegexStr(this.s, 0x4),
regex: rawToRegexStr(this.s + '^'),
compiled: this.compile()
};
};
Expand Down Expand Up @@ -627,13 +632,10 @@ FilterGenericHnAnchored.prototype.match = function(url) {
return this.re.test(url);
};

FilterGenericHnAnchored.prototype.reSourceOffset =
(new RegExp(rawToRegexStr.reTextHostnameAnchor)).source.length;

FilterGenericHnAnchored.prototype.logData = function() {
var out = {
raw: '||' + this.s,
regex: this.re.source.slice(this.reSourceOffset),
regex: rawToRegexStr(this.s, this.anchor & ~0x4),
compiled: this.compile()
};
return out;
Expand Down

0 comments on commit 8b4b1fa

Please sign in to comment.