Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/matcher.js

Issue 5991150368325632: Issue 616 - Add specificOnly parameter to matchesAny (Closed)
Patch Set: Make specificOnly parameter for matchesAny actually work... Created March 11, 2015, 5:04 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/matcher.js
diff --git a/lib/matcher.js b/lib/matcher.js
index 8494b6e4cf18660799aea2bc16441c271f5f220e..e169fb5dc88734419be00a0aa11b44ad6a0f7b6a 100644
--- a/lib/matcher.js
+++ b/lib/matcher.js
@@ -165,13 +165,15 @@ Matcher.prototype = {
/**
* Checks whether the entries for a particular keyword match a URL
*/
- _checkEntryMatch: function(keyword, location, contentType, docDomain, thirdParty, sitekey)
+ _checkEntryMatch: function(keyword, location, contentType, docDomain, thirdParty, sitekey, specificOnly)
{
let list = this.filterByKeyword[keyword];
for (let i = 0; i < list.length; i++)
{
let filter = list[i];
- if (filter.matches(location, contentType, docDomain, thirdParty, sitekey))
+ if (filter.matches(location, contentType, docDomain, thirdParty, sitekey) &&
Sebastian Noack 2015/03/12 11:36:21 Since the filter match is certainly the most expen
Sebastian Noack 2015/03/12 11:36:21 This is a very long chain of conditions. How about
kzar 2015/03/12 17:08:09 Done.
kzar 2015/03/12 17:08:09 Done.
+ (!specificOnly || filter instanceof WhitelistFilter ||
+ !(!filter.domains || filter.domains[""])))
Sebastian Noack 2015/03/12 11:36:21 Isn't this the same as (filter.domains && !filter.
kzar 2015/03/12 17:08:09 Done.
return filter;
}
return null;
@@ -184,9 +186,10 @@ Matcher.prototype = {
* @param {String} docDomain domain name of the document that loads the URL
* @param {Boolean} thirdParty should be true if the URL is a third-party request
* @param {String} sitekey public key provided by the document
+ * @param {Boolean} specificOnly should be true if generic matches should be ignored
* @return {RegExpFilter} matching filter or null
*/
- matchesAny: function(location, contentType, docDomain, thirdParty, sitekey)
+ matchesAny: function(location, contentType, docDomain, thirdParty, sitekey, specificOnly)
{
let candidates = location.toLowerCase().match(/[a-z0-9%]{3,}/g);
if (candidates === null)
@@ -197,7 +200,7 @@ Matcher.prototype = {
let substr = candidates[i];
if (substr in this.filterByKeyword)
{
- let result = this._checkEntryMatch(substr, location, contentType, docDomain, thirdParty, sitekey);
+ let result = this._checkEntryMatch(substr, location, contentType, docDomain, thirdParty, sitekey, specificOnly);
if (result)
return result;
}
@@ -347,7 +350,7 @@ CombinedMatcher.prototype =
* simultaneously. For parameters see Matcher.matchesAny().
* @see Matcher#matchesAny
*/
- matchesAnyInternal: function(location, contentType, docDomain, thirdParty, sitekey)
+ matchesAnyInternal: function(location, contentType, docDomain, thirdParty, sitekey, specificOnly)
{
let candidates = location.toLowerCase().match(/[a-z0-9%]{3,}/g);
if (candidates === null)
@@ -365,7 +368,7 @@ CombinedMatcher.prototype =
return result;
}
if (substr in this.blacklist.filterByKeyword && blacklistHit === null)
- blacklistHit = this.blacklist._checkEntryMatch(substr, location, contentType, docDomain, thirdParty, sitekey);
+ blacklistHit = this.blacklist._checkEntryMatch(substr, location, contentType, docDomain, thirdParty, sitekey, specificOnly);
}
return blacklistHit;
},
@@ -373,13 +376,13 @@ CombinedMatcher.prototype =
/**
* @see Matcher#matchesAny
*/
- matchesAny: function(location, contentType, docDomain, thirdParty, sitekey)
+ matchesAny: function(location, contentType, docDomain, thirdParty, sitekey, specificOnly)
{
- let key = location + " " + contentType + " " + docDomain + " " + thirdParty + " " + sitekey;
+ let key = location + " " + contentType + " " + docDomain + " " + thirdParty + " " + sitekey + " " + specificOnly;
if (key in this.resultCache)
return this.resultCache[key];
- let result = this.matchesAnyInternal(location, contentType, docDomain, thirdParty, sitekey);
+ let result = this.matchesAnyInternal(location, contentType, docDomain, thirdParty, sitekey, specificOnly);
if (this.cacheEntries >= CombinedMatcher.maxCacheEntries)
{
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld