diff options
author | Ruben Rodriguez <ruben@fsf.org> | 2019-04-29 17:55:18 -0400 |
---|---|---|
committer | Ruben Rodriguez <ruben@fsf.org> | 2019-04-29 17:55:18 -0400 |
commit | ef4efa91207e1ad42b4a0bf1d54a14e5c1bea298 (patch) | |
tree | 5d67683fdf4f6e2de356bfcb6096820cd380b143 /bg | |
parent | c6fafeed2ace4abd083b8e33d0846987dc9333fc (diff) | |
parent | b4ab7ef958d7d3d0761650b1404bf286d05f26cd (diff) |
Merge branch 'master' of ssh://pagure.io/librejs
Diffstat (limited to 'bg')
-rw-r--r-- | bg/ListManager.js | 35 | ||||
-rw-r--r-- | bg/ResponseProcessor.js | 2 |
2 files changed, 30 insertions, 7 deletions
diff --git a/bg/ListManager.js b/bg/ListManager.js index 2f5f74e..745e599 100644 --- a/bg/ListManager.js +++ b/bg/ListManager.js @@ -36,13 +36,13 @@ class ListManager { } async whitelist(...keys) { - ListManager.move(this.lists.blacklist, this.lists.whitelist, ...keys); + await ListManager.move(this.lists.blacklist, this.lists.whitelist, ...keys); } async blacklist(...keys) { - ListManager.move(this.lists.whitelist, this.lists.blacklist, ...keys); + await ListManager.move(this.lists.whitelist, this.lists.blacklist, ...keys); } async forget(...keys) { - await Promise.all(Object.values(this.lists).map(l => l.remove(...keys))); + await Promise.all(Object.values(this.lists).map(async l => await l.remove(...keys))); } /* key is a string representing either a URL or an optional path with a trailing (hash). @@ -62,10 +62,11 @@ class ListManager { if (!match) { let url = ListStore.urlItem(key); let site = ListStore.siteItem(key); - return (blacklist.contains(url) || blacklist.contains(site)) + return (blacklist.contains(url) || ListManager.siteMatch(site, blacklist) ? "blacklisted" - : whitelist.contains(url) || whitelist.contains(site) - ? "whitelisted" : defValue; + : whitelist.contains(url) || ListManager.siteMatch(site, whitelist) + ? "whitelisted" : defValue + ); } let [hashItem, srcHash] = match; // (hash), hash @@ -74,6 +75,28 @@ class ListManager { ? "whitelisted" : defValue; } + + /* + Matches by whole site ("http://some.domain.com/*") supporting also + wildcarded subdomains ("https://*.domain.com/*"). + */ + static siteMatch(url, list) { + let site = ListStore.siteItem(url); + if (list.contains(site)) { + return site; + } + site = site.replace(/^([\w-]+:\/\/)?(\w)/, "$1*.$2"); + for (;;) { + if (list.contains(site)) { + return site; + } + let oldKey = site; + site = site.replace(/(?:\*\.)*\w+(?=\.)/, "*"); + if (site === oldKey) { + return null; + } + } + } } module.exports = { ListManager }; diff --git a/bg/ResponseProcessor.js b/bg/ResponseProcessor.js index 1aa89de..2c613c9 100644 --- a/bg/ResponseProcessor.js +++ b/bg/ResponseProcessor.js @@ -78,7 +78,7 @@ class ResponseTextFilter { let res = await handler.pre(response); if (res) return res; if (handler.post) handler = handler.post; - if (typeof handler !== "function") ResponseProcessor.ACCEPT; + if (typeof handler !== "function") return ResponseProcessor.ACCEPT; } let {requestId, responseHeaders} = request; |