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

Unified Diff: lib/abp2blocklist.js

Issue 29443587: Noissue - Do not add subdomain wildcard if subdomain excluded (Closed) Base URL: https://hg.adblockplus.org/abp2blocklist
Patch Set: Use includes Created May 22, 2017, 4:06 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 | test/abp2blocklist.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/abp2blocklist.js
===================================================================
--- a/lib/abp2blocklist.js
+++ b/lib/abp2blocklist.js
@@ -59,16 +59,30 @@
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
function matchDomain(domain)
{
return "^https?://([^/:]*\\.)?" + escapeRegExp(domain).toLowerCase() + "[/:]";
}
+function findSubdomainsInList(domain, list)
+{
+ let subdomains = [];
+ let suffixLength = domain.length + 1;
+
+ for (let name of list)
+ {
+ if (name.length > suffixLength && name.slice(-suffixLength) == "." + domain)
+ subdomains.push(name.slice(0, -suffixLength));
+ }
+
+ return subdomains;
+}
+
function convertElemHideFilter(filter, elemhideSelectorExceptions)
{
let included = [];
let excluded = [];
let rules = [];
parseDomains(filter.domains, included, excluded);
@@ -263,19 +277,44 @@
if (trigger["resource-type"].length == 0)
return;
}
if (filter.thirdParty != null)
trigger["load-type"] = [filter.thirdParty ? "third-party" : "first-party"];
if (included.length > 0)
- trigger["if-domain"] = included.map(name => "*" + name);
+ {
+ trigger["if-domain"] = [];
+
+ for (let name of included)
+ {
+ // If this is a blocking filter or an element hiding filter, add the
+ // subdomain wildcard only if no subdomains have been excluded.
+ let notSubdomains = null;
+ if ((filter instanceof filterClasses.BlockingFilter ||
+ filter instanceof filterClasses.ElemHideFilter) &&
+ (notSubdomains = findSubdomainsInList(name, excluded)).length > 0)
+ {
+ trigger["if-domain"].push(name);
+
+ // Add the "www" prefix but only if it hasn't been excluded.
+ if (!notSubdomains.includes("www"))
+ trigger["if-domain"].push("www." + name);
+ }
+ else
+ {
+ trigger["if-domain"].push("*" + name);
+ }
+ }
+ }
else if (excluded.length > 0)
+ {
trigger["unless-domain"] = excluded.map(name => "*" + name);
+ }
rules.push({trigger: trigger, action: {type: action}});
}
function hasNonASCI(obj)
{
if (typeof obj == "string")
{
« no previous file with comments | « no previous file | test/abp2blocklist.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld