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 || |
Sebastian Noack
2017/05/21 20:56:13
Ẁhy do we have to explicitly check for BlockingFil
Manish Jethani
2017/05/21 21:49:05
Because what is desired in the case of whitelistin
Sebastian Noack
2017/05/22 08:06:11
That might be a good point. It seems to be better
|
+ 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.some(name => name == "www")) |
Sebastian Noack
2017/05/21 20:56:13
Is this check actually correct? What if the domain
Manish Jethani
2017/05/21 21:49:05
Can you give a more complete example of where this
Sebastian Noack
2017/05/22 08:06:11
So in case of a filter like this:
$domain=example
Manish Jethani
2017/05/22 10:37:39
In this case the code would be comparing with "foo
Sebastian Noack
2017/05/22 11:08:59
Alright. But I think it still can be slightly simp
Manish Jethani
2017/05/22 16:07:08
Done.
|
+ 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") |
{ |