mirror of https://github.com/gorhill/uBlock.git
generate better regex for hostname-anchored generic filters
This commit is contained in:
parent
c31d29c2e3
commit
b2e89c9ece
|
@ -200,7 +200,7 @@ var rawToRegexStr = function(s, anchor) {
|
||||||
.replace(me.escape3, '')
|
.replace(me.escape3, '')
|
||||||
.replace(me.escape4, '[^ ]*?');
|
.replace(me.escape4, '[^ ]*?');
|
||||||
if ( anchor & 0x4 ) {
|
if ( anchor & 0x4 ) {
|
||||||
reStr = '[0-9a-z.-]*?' + reStr;
|
reStr = rawToRegexStr.reTextHostnameAnchor + reStr;
|
||||||
} else if ( anchor & 0x2 ) {
|
} else if ( anchor & 0x2 ) {
|
||||||
reStr = '^' + reStr;
|
reStr = '^' + reStr;
|
||||||
}
|
}
|
||||||
|
@ -213,6 +213,7 @@ rawToRegexStr.escape1 = /[.+?${}()|[\]\\]/g;
|
||||||
rawToRegexStr.escape2 = /\^/g;
|
rawToRegexStr.escape2 = /\^/g;
|
||||||
rawToRegexStr.escape3 = /^\*|\*$/g;
|
rawToRegexStr.escape3 = /^\*|\*$/g;
|
||||||
rawToRegexStr.escape4 = /\*/g;
|
rawToRegexStr.escape4 = /\*/g;
|
||||||
|
rawToRegexStr.reTextHostnameAnchor = '^[a-z-]+://(?:[^/?#]+\\.)?';
|
||||||
|
|
||||||
var filterFingerprinter = µb.CompiledLineWriter.fingerprint;
|
var filterFingerprinter = µb.CompiledLineWriter.fingerprint;
|
||||||
|
|
||||||
|
@ -627,10 +628,13 @@ FilterGenericHnAnchored.prototype.match = function(url) {
|
||||||
return matchStart !== -1 && isHnAnchored(url, matchStart);
|
return matchStart !== -1 && isHnAnchored(url, matchStart);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
FilterGenericHnAnchored.prototype.reSourceOffset =
|
||||||
|
(new RegExp(rawToRegexStr.reTextHostnameAnchor)).source.length;
|
||||||
|
|
||||||
FilterGenericHnAnchored.prototype.logData = function() {
|
FilterGenericHnAnchored.prototype.logData = function() {
|
||||||
var out = {
|
var out = {
|
||||||
raw: '||' + this.s,
|
raw: '||' + this.s,
|
||||||
regex: this.re.source,
|
regex: this.re.source.slice(this.reSourceOffset),
|
||||||
compiled: this.compile()
|
compiled: this.compile()
|
||||||
};
|
};
|
||||||
return out;
|
return out;
|
||||||
|
|
Loading…
Reference in New Issue