diff options
author | hackademix | 2018-09-04 18:48:14 +0200 |
---|---|---|
committer | hackademix | 2018-09-04 19:28:16 +0200 |
commit | 26470b84f681b7db9e500bb4503eab7b8b202879 (patch) | |
tree | 842228c86ab61eb149868752479b53f19b05d9c9 /src/bg/ChildPolicies.js | |
parent | df149a5a5578f3d34ba404836fccca8d2cfa508e (diff) | |
download | noscript-26470b84f681b7db9e500bb4503eab7b8b202879.tar.gz noscript-26470b84f681b7db9e500bb4503eab7b8b202879.tar.xz noscript-26470b84f681b7db9e500bb4503eab7b8b202879.zip |
Transparent support for FQDNs and better management of file:/// URLs.
Diffstat (limited to 'src/bg/ChildPolicies.js')
-rw-r--r-- | src/bg/ChildPolicies.js | 26 |
1 files changed, 14 insertions, 12 deletions
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) { |