From 26470b84f681b7db9e500bb4503eab7b8b202879 Mon Sep 17 00:00:00 2001 From: hackademix Date: Tue, 4 Sep 2018 18:48:14 +0200 Subject: Transparent support for FQDNs and better management of file:/// URLs. --- src/bg/ChildPolicies.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'src/bg') diff --git a/src/bg/ChildPolicies.js b/src/bg/ChildPolicies.js index 4fceb0f..99402ca 100644 --- a/src/bg/ChildPolicies.js +++ b/src/bg/ChildPolicies.js @@ -71,19 +71,12 @@ let hasProtocol = site.match(protocolRx); let mp = site; if (hasProtocol) { - try { - let url = new URL(site); - url.port = ""; - url.search = ""; - url.hash = ""; - mp = url.href; - } catch (e) { - return false; - } + mp = Sites.cleanUrl(mp); + if (!mp) return false; } else { let protocol = Sites.isSecureDomainKey(site) ? "https://" : "*://"; - let hostname = Sites.toggleSecureDomainKey(site, false) - .replace(portRx, ''); + let hostname = Sites.toggleSecureDomainKey(site, false).replace(portRx, ''); + if (!tld.preserveFQDNs) hostname = tld.normalize(hostname); mp = `${protocol}*.${hostname}`; if (!hostname.includes("/")) mp += "/"; } @@ -92,7 +85,16 @@ mp.endsWith("/") ? `${mp}*` : [mp, `${mp}?*`, `${mp}#*`]); }; - let siteKeys2MatchPatterns = keys => keys && flatten(keys.map(siteKey2MatchPattern)).filter(p => !!p) || []; + let withFQDNs = patterns => { + return tld.preserveFQDNs ? patterns : patterns.concat( + patterns.map(p => p.replace(/^(?:\w+|\*):\/\/[^/]*[^./]/, '$&.')) + ); + } + + let siteKeys2MatchPatterns = keys => + keys && withFQDNs(flatten(keys.map(siteKey2MatchPattern)) + .filter(p => !!p)) + || []; var ChildPolicies = { async storeTabInfo(tabId, info) { -- cgit v1.2.3