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