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

Unified Diff: lib/abp2blocklist.js

Issue 29438577: Issue 5248 - Use wildcard to match any subdomains (Closed) Base URL: https://hg.adblockplus.org/abp2blocklist
Patch Set: Created May 16, 2017, 1:06 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 | package.json » ('j') | test/abp2blocklist.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/abp2blocklist.js
===================================================================
--- a/lib/abp2blocklist.js
+++ b/lib/abp2blocklist.js
@@ -15,17 +15,16 @@
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
/** @module abp2blocklist */
"use strict";
let filterClasses = require("filterClasses");
-let tldjs = require("tldjs");
let punycode = require("punycode");
const selectorLimit = 5000;
const typeMap = filterClasses.RegExpFilter.typeMap;
const whitelistableRequestTypes = (typeMap.IMAGE
| typeMap.STYLESHEET
| typeMap.SCRIPT
| typeMap.FONT
@@ -210,45 +209,30 @@
typeMap.OTHER))
types.push("raw");
if (filter.contentType & typeMap.SUBDOCUMENT)
types.push("document");
return types;
}
-function addDomainPrefix(domains)
-{
- let result = [];
-
- for (let domain of domains)
- {
- result.push(domain);
-
- if (tldjs.getDomain(domain) == domain)
- result.push("www." + domain);
- }
-
- return result;
-}
-
function convertFilterAddRules(rules, filter, action, withResourceTypes)
{
let parsed = parseFilterRegexpSource(filter.regexpSource);
// For the special case of $document whitelisting filters with just a domain
// we can generate an equivalent blocking rule exception using if-domain.
if (filter instanceof filterClasses.WhitelistFilter &&
filter.contentType & typeMap.DOCUMENT &&
parsed.justHostname)
{
rules.push({
trigger: {
"url-filter": ".*",
- "if-domain": addDomainPrefix([parsed.hostname])
+ "if-domain": ["*" + parsed.hostname]
},
action: {type: "ignore-previous-rules"}
});
// If the filter contains other supported options we'll need to generate
// further rules for it, but if not we can simply return now.
if (!(filter.contentType & whitelistableRequestTypes))
return;
}
@@ -279,19 +263,19 @@
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"] = addDomainPrefix(included);
+ trigger["if-domain"] = included.map(name => "*" + name);
else if (excluded.length > 0)
- trigger["unless-domain"] = addDomainPrefix(excluded);
+ 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 | package.json » ('j') | test/abp2blocklist.js » ('J')

Powered by Google App Engine
This is Rietveld