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: Check whitelist for whitelist-only types Created Oct. 21, 2018, 2:43 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,47 @@
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)
Manish Jethani 2018/10/21 15:00:23 If the type mask includes no types other than DOCU
{
- 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; i < l; i++)
{
+ let substr = candidates[i];
blacklistHit = this.blacklist._checkEntryMatch(
substr, location, typeMask, docDomain, thirdParty, sitekey,
specificOnly
);
+ if (blacklistHit)
+ break;
}
}
- return blacklistHit;
+
+ if (blacklistHit || (typeMask & WHITELIST_ONLY_TYPES) != 0)
Manish Jethani 2018/10/21 15:00:22 If the type mask includes DOCUMENT, ELEMHIDE, GENE
+ {
+ for (let i = 0, l = candidates.length; i < l; i++)
+ {
+ let substr = candidates[i];
+ whitelistHit = this.whitelist._checkEntryMatch(
+ substr, location, typeMask, docDomain, thirdParty, sitekey
+ );
+ if (whitelistHit)
+ break;
+ }
+ }
+
+ 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