aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/patterns.js9
1 files changed, 8 insertions, 1 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 !== "");