summaryrefslogtreecommitdiff
path: root/src/bg
diff options
context:
space:
mode:
authorhackademix2018-09-10 19:10:32 +0200
committerhackademix2018-09-10 19:10:32 +0200
commit48053d96d44abbfa3c659e5fc817d998dda2bb35 (patch)
treee7c8b36edf2db7544c5e8fd543f6e28579e315a8 /src/bg
parent2b45fcb9a42c0acb2f5a88338c67244ae6c4fb8f (diff)
downloadnoscript-48053d96d44abbfa3c659e5fc817d998dda2bb35.tar.gz
noscript-48053d96d44abbfa3c659e5fc817d998dda2bb35.tar.xz
noscript-48053d96d44abbfa3c659e5fc817d998dda2bb35.zip
Better IPV6 support.
Diffstat (limited to 'src/bg')
-rw-r--r--src/bg/ChildPolicies.js25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/bg/ChildPolicies.js b/src/bg/ChildPolicies.js
index 7f94ce0..7df3253 100644
--- a/src/bg/ChildPolicies.js
+++ b/src/bg/ChildPolicies.js
@@ -56,7 +56,7 @@
let protocolRx = /^(\w+):/i;
let pathRx = /(?:[^:/]\/|:\/{3})$/;
let portRx = /:\d+(?=\/|$)/;
- let validMatchPatternRx = /^(?:\*|(?:http|ws|ftp)s?|file):\/\/(?:\*|(?:\*\.)?[\w\u0100-\uf000][\w\u0100-\uf000.-]*)?\/(\*|[^*]*)$/;
+ let validMatchPatternRx = /^(?:\*|(?:http|ws|ftp)s?|file):\/\/(?:\*|(?:\*\.)?[\w\u0100-\uf000][\w\u0100-\uf000.-]*|\[[\w:]+\])?\/(\*|[^*]*)$/;
let validMatchPattern = mp => validMatchPatternRx.test(mp);
@@ -67,23 +67,30 @@
mp = Sites.cleanUrl(mp);
if (!mp) return false;
} else {
- let protocol = Sites.isSecureDomainKey(site) ? "https://" : "*://";
- mp = `${protocol}*`;
+ mp = Sites.isSecureDomainKey(site) ? "https://" : "*://";
let hostname = Sites.toggleSecureDomainKey(site, false).replace(portRx, '');
if (hostname && hostname !== ".") {
- if (!tld.preserveFQDNs) hostname = tld.normalize(hostname);
- mp += hostname.startsWith(".") ? hostname : `.${hostname}`;
+ if (tld.isIp(hostname) || hostname.includes("*")) {
+ mp += hostname;
+ } else {
+ if (!tld.preserveFQDNs) hostname = tld.normalize(hostname);
+ mp += hostname.startsWith(".") ? `*${hostname}` : `*.${hostname}`;
+ }
+ } else {
+ mp += "*";
}
if (!(hostname && hostname.includes("/"))) mp += "/";
}
- return validMatchPatternRx.test(mp) && (
- mp.endsWith("/") ? `${mp}*` : [mp, `${mp}?*`, `${mp}#*`]);
+ return validMatchPattern(mp) &&
+ (mp.endsWith("/") ? `${mp}*` : [mp, `${mp}?*`, `${mp}#*`]);
};
let withFQDNs = patterns => {
- return tld.preserveFQDNs ? patterns : patterns.concat(
- patterns.map(p => p.replace(/^(?:\w+|\*):\/\/[^/]*[^.*/]/, '$&.')
+ if (tld.preserveFQDNs) return patterns;
+ let rx = /^(?:\w+|\*):\/\/([^/]*[^.*/])/;
+ return patterns.concat(
+ patterns.map(p => p.replace(rx, (m, host) => tld.isIp(host) ? m : m + ".")
).filter(validMatchPattern)
);
}