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

Unified Diff: lib/matcher.js

Issue 29896562: Issue 7003 - Look up whitelist filter only if URL is blocked (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Inline access to blacklist and whitelist Created Oct. 21, 2018, 3:45 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
===================================================================
--- a/lib/matcher.js
+++ b/lib/matcher.js
@@ -17,31 +17,41 @@
"use strict";
/**
* @fileOverview Matcher class implementing matching addresses against
* a list of filters.
*/
-const {WhitelistFilter} = require("./filterClasses");
+const {RegExpFilter, WhitelistFilter} = require("./filterClasses");
/**
* Regular expression for matching a keyword in a filter.
* @type {RegExp}
*/
const keywordRegExp = /[^a-z0-9%*][a-z0-9%]{3,}(?=[^a-z0-9%*])/;
/**
* Regular expression for matching all keywords in a filter.
* @type {RegExp}
*/
const allKeywordsRegExp = new RegExp(keywordRegExp, "g");
/**
+ * Bitmask for "types" that are for exception rules only, like
+ * <code>$document</code>, <code>$elemhide</code>, and so on.
+ * @type {number}
+ */
+const WHITELIST_ONLY_TYPES = RegExpFilter.typeMap.DOCUMENT |
+ RegExpFilter.typeMap.ELEMHIDE |
+ RegExpFilter.typeMap.GENERICHIDE |
+ RegExpFilter.typeMap.GENERICBLOCK;
+
+/**
* Checks whether a particular filter is slow.
* @param {RegExpFilter} filter
* @returns {boolean}
*/
function isSlowFilter(filter)
{
return !filter.pattern || !keywordRegExp.test(filter.pattern);
}
@@ -315,34 +325,41 @@
matchesAnyInternal(location, typeMask, docDomain, thirdParty, sitekey,
specificOnly)
{
let candidates = location.toLowerCase().match(/[a-z0-9%]{3,}/g);
if (candidates === null)
candidates = [];
candidates.push("");
+ let whitelistHit = null;
let blacklistHit = null;
- for (let i = 0, l = candidates.length; i < l; i++)
+
+ if ((typeMask & ~WHITELIST_ONLY_TYPES) != 0)
Sebastian Noack 2018/10/21 22:41:39 I wonder if this logic is necessary. Shouldn't cal
Manish Jethani 2018/10/22 11:05:16 I like the idea, but we would lose out on the cach
Sebastian Noack 2018/10/22 15:04:31 No strong opinion either way, but in case we go wi
Manish Jethani 2018/10/22 20:39:30 We will be doing this as part of this: https://co
Manish Jethani 2018/10/22 21:16:19 I've added comments to make it clearer.
Sebastian Noack 2018/10/22 22:12:35 I don't see any changes in the current patch there
Manish Jethani 2018/10/22 22:57:56 Yes, I'll suggest that change there if we agree on
{
- let substr = candidates[i];
- let result = this.whitelist._checkEntryMatch(
- substr, location, typeMask, docDomain, thirdParty, sitekey
- );
- if (result)
- return result;
- if (blacklistHit === null)
+ for (let i = 0, l = candidates.length; !blacklistHit && i < l; i++)
{
- blacklistHit = this.blacklist._checkEntryMatch(
- substr, location, typeMask, docDomain, thirdParty, sitekey,
- specificOnly
- );
+ blacklistHit = this.blacklist._checkEntryMatch(candidates[i], location,
+ typeMask, docDomain,
+ thirdParty, sitekey,
+ specificOnly);
}
}
- return blacklistHit;
+
+ if (blacklistHit || (typeMask & WHITELIST_ONLY_TYPES) != 0)
+ {
+ for (let i = 0, l = candidates.length; !whitelistHit && i < l; i++)
+ {
+ whitelistHit = this.whitelist._checkEntryMatch(candidates[i], location,
+ typeMask, docDomain,
+ thirdParty, sitekey);
+ }
+ }
+
+ return whitelistHit || blacklistHit;
}
/**
* @see Matcher#matchesAny
* @inheritdoc
*/
matchesAny(location, typeMask, docDomain, thirdParty, sitekey, specificOnly)
{
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld