This commit is contained in:
gorhill 2015-03-17 09:39:03 -04:00
parent c81a9925b2
commit d1a1e196ce

View file

@ -165,16 +165,29 @@ var isFirstParty = function(firstPartyDomain, hostname) {
return c === '.' || c === ''; return c === '.' || c === '';
}; };
// https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions var alwaysTruePseudoRegex = {
test: function() {
return true;
}
};
var strToRegex = function(s, anchor) { var strToRegex = function(s, anchor) {
// https://github.com/gorhill/uBlock/issues/1038
// Special case: always match.
if ( s === '*' ) {
return alwaysTruePseudoRegex;
}
// https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions
var reStr = s.replace(/[.+?^${}()|[\]\\]/g, '\\$&') var reStr = s.replace(/[.+?^${}()|[\]\\]/g, '\\$&')
.replace(/\*/g, '.*'); .replace(/\*/g, '.*');
if ( anchor < 0 ) { if ( anchor < 0 ) {
reStr = '^' + reStr; reStr = '^' + reStr;
} else if ( anchor > 0 ) { } else if ( anchor > 0 ) {
reStr += reStr + '$'; reStr += reStr + '$';
} }
//console.debug('µBlock.staticNetFilteringEngine: created RegExp("%s")', reStr); //console.debug('µBlock.staticNetFilteringEngine: created RegExp("%s")', reStr);
return new RegExp(reStr); return new RegExp(reStr);
}; };
@ -1082,7 +1095,7 @@ var getFilterClass = function(details) {
return FilterRegex; return FilterRegex;
} }
var s = details.f; var s = details.f;
if ( s.indexOf('*') !== -1 ) { if ( s.indexOf('*') !== -1 || details.token === '*' ) {
if ( details.hostnameAnchored ) { if ( details.hostnameAnchored ) {
return FilterGenericHnAnchored; return FilterGenericHnAnchored;
} }
@ -1113,7 +1126,7 @@ var getHostnameBasedFilterClass = function(details) {
return FilterRegexHostname; return FilterRegexHostname;
} }
var s = details.f; var s = details.f;
if ( s.indexOf('*') !== -1 ) { if ( s.indexOf('*') !== -1 || details.token === '*' ) {
if ( details.hostnameAnchored ) { if ( details.hostnameAnchored ) {
return FilterGenericHnAnchoredHostname; return FilterGenericHnAnchoredHostname;
} }
@ -1380,8 +1393,7 @@ FilterParser.prototype.parse = function(raw) {
// nothing left? // nothing left?
if ( s === '' ) { if ( s === '' ) {
this.unsupported = true; s = '*';
return this;
} }
// plain hostname? // plain hostname?
@ -1455,27 +1467,37 @@ FilterParser.prototype.makeToken = function() {
return; return;
} }
var s = this.f;
// https://github.com/gorhill/uBlock/issues/1038
// Match any URL.
if ( s === '*' ) {
this.token = '*';
return;
}
var matches; var matches;
// Hostname-anchored with no wildcard always have a token index of 0. // Hostname-anchored with no wildcard always have a token index of 0.
if ( this.hostnameAnchored && this.f.indexOf('*') === -1 ) { if ( this.hostnameAnchored && s.indexOf('*') === -1 ) {
matches = findHostnameToken(this.f); matches = findHostnameToken(s);
if ( !matches || matches[0].length === 0 ) { if ( !matches || matches[0].length === 0 ) {
return; return;
} }
this.tokenBeg = matches.index; this.tokenBeg = matches.index;
this.tokenEnd = reHostnameToken.lastIndex; this.tokenEnd = reHostnameToken.lastIndex;
this.token = this.f.slice(this.tokenBeg, this.tokenEnd); this.token = s.slice(this.tokenBeg, this.tokenEnd);
return; return;
} }
matches = findFirstGoodToken(this.f); matches = findFirstGoodToken(s);
if ( matches === null || matches[0].length === 0 ) { if ( matches === null || matches[0].length === 0 ) {
this.token = '*';
return; return;
} }
this.tokenBeg = matches.index; this.tokenBeg = matches.index;
this.tokenEnd = reGoodToken.lastIndex; this.tokenEnd = reGoodToken.lastIndex;
this.token = this.f.slice(this.tokenBeg, this.tokenEnd); this.token = s.slice(this.tokenBeg, this.tokenEnd);
}; };
/******************************************************************************/ /******************************************************************************/