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

Unified Diff: lib/matcher.js

Issue 30018560: Issue 7312 - Ignore lone pure generic filters for specific-only queries (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Feb. 26, 2019, 11:48 a.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 | test/matcher.js » ('j') | test/matcher.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/matcher.js
===================================================================
--- a/lib/matcher.js
+++ b/lib/matcher.js
@@ -463,28 +463,25 @@
}
}
}
return null;
}
_checkEntryMatchSimple(keyword, location, typeMask, docDomain, thirdParty,
- sitekey, specificOnly, collection)
+ sitekey, collection)
{
let filters = this._simpleFiltersByKeyword.get(keyword);
if (filters)
{
let lowerCaseLocation = location.toLowerCase();
for (let filter of filters)
{
- if (specificOnly && !(filter instanceof WhitelistFilter))
Manish Jethani 2019/02/26 11:54:24 There's no need for this check. We already decided
- continue;
-
if (filter.matchesLocation(location, lowerCaseLocation))
{
if (!collection)
return filter;
collection.push(filter);
}
}
@@ -499,18 +496,17 @@
let filtersForType = this._filterMapsByType.get(typeMask);
if (filtersForType)
{
let filters = filtersForType.get(keyword);
if (filters)
{
for (let filter of filters)
{
- if (specificOnly && filter.isGeneric() &&
Manish Jethani 2019/02/26 11:54:24 We decided not to do these checks in Matcher (chan
- !(filter instanceof WhitelistFilter))
+ if (specificOnly && filter.isGeneric())
continue;
if (filter.matches(location, typeMask, docDomain, thirdParty,
sitekey))
{
if (!collection)
return filter;
@@ -533,19 +529,26 @@
{
return this._matchFiltersByDomain(filtersByDomain, location, typeMask,
docDomain, thirdParty, sitekey,
specificOnly, collection);
}
// Because of the memory optimization in the add function, most of the
// time this will be a filter rather than a map.
- return this._matchFilterWithoutDomain(filtersByDomain, location,
- typeMask, thirdParty, sitekey,
- collection);
+
+ // Also see #7312: If it's a single filter, it's always the equivalent of
+ // Map { "" => Map { filter => true } } (i.e. applies to any domain). If
+ // the specific-only flag is set, we skip it.
+ if (!specificOnly)
+ {
+ return this._matchFilterWithoutDomain(filtersByDomain, location,
+ typeMask, thirdParty, sitekey,
+ collection);
+ }
}
return null;
}
/**
* Checks whether the entries for a particular keyword match a URL
* @param {string} keyword
@@ -566,17 +569,17 @@
specificOnly, collection)
{
// We need to skip the simple (location-only) filters if the type mask does
// not contain any default content types.
if (!specificOnly && (typeMask & DEFAULT_TYPES) != 0)
{
let filter = this._checkEntryMatchSimple(keyword, location, typeMask,
docDomain, thirdParty, sitekey,
- specificOnly, collection);
+ collection);
if (filter)
return filter;
}
// If the type mask contains a non-default type (first condition) and it is
// the only type in the mask (second condition), we can use the
// type-specific map, which typically contains a lot fewer filters. This
// enables faster lookups for whitelisting types like $document, $elemhide,
« no previous file with comments | « no previous file | test/matcher.js » ('j') | test/matcher.js » ('J')

Powered by Google App Engine
This is Rietveld