summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2021-08-27 10:52:52 +0200
committerWojtek Kosior <koszko@koszko.org>2021-08-27 10:52:52 +0200
commit48f76d7004da4bd4998d0c79266c62f893cfa7d3 (patch)
tree44b29505c9e466f1acb4f3aba5fb026fde834bd0
parent538376341e9a50ebd350897fe26f43c433f0ee06 (diff)
downloadbrowser-extension-48f76d7004da4bd4998d0c79266c62f893cfa7d3.tar.gz
browser-extension-48f76d7004da4bd4998d0c79266c62f893cfa7d3.zip
add support for `ftp://' protocol
-rw-r--r--common/patterns.js9
-rw-r--r--content/main.js2
2 files changed, 9 insertions, 2 deletions
diff --git a/common/patterns.js b/common/patterns.js
index 0a322b0..ebb55ab 100644
--- a/common/patterns.js
+++ b/common/patterns.js
@@ -7,6 +7,7 @@
const proto_regex = /^(\w+):\/\/(.*)$/;
+const user_re = "[^/?#@]+@"
const domain_re = "[^/?#]+";
const path_re = "[^?#]*";
const query_re = "\\??[^#]*";
@@ -15,6 +16,8 @@ const http_regex = new RegExp(`^(${domain_re})(${path_re})(${query_re}).*`);
const file_regex = new RegExp(`^(${path_re}).*`);
+const ftp_regex = new RegExp(`^(${user_re})?(${domain_re})(${path_re}).*`);
+
function deconstruct_url(url)
{
const proto_match = proto_regex.exec(url);
@@ -25,14 +28,18 @@ function deconstruct_url(url)
if (deco.proto === "file") {
deco.path = file_regex.exec(proto_match[2])[1];
+ } else if (deco.proto === "ftp") {
+ [deco.domain, deco.path] = ftp_regex.exec(proto_match[2]).slice(2, 4);
} else {
const http_match = http_regex.exec(proto_match[2]);
if (!http_match)
return undefined;
[deco.domain, deco.path, deco.query] = http_match.slice(1, 4);
- deco.domain = deco.domain.split(".");
}
+ if (deco.domain)
+ deco.domain = deco.domain.split(".");
+
const leading_dash = deco.path[0] === "/";
deco.trailing_dash = deco.path[deco.path.length - 1] === "/";
deco.path = deco.path.split("/").filter(s => s !== "");
diff --git a/content/main.js b/content/main.js
index 06d3bf1..6c97350 100644
--- a/content/main.js
+++ b/content/main.js
@@ -109,7 +109,7 @@ if (!is_privileged_url(document.URL)) {
document.cookie = `hachette-${signature}=; Max-Age=-1;`;
} else {
const scheme = /^([^:]*)/.exec(document.URL)[1];
- const known_scheme = ["file"].includes(scheme);
+ const known_scheme = ["file", "ftp"].includes(scheme);
if (!known_scheme)
console.warn(`Unknown url scheme: \`${scheme}'!`);