From 48f76d7004da4bd4998d0c79266c62f893cfa7d3 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Fri, 27 Aug 2021 10:52:52 +0200 Subject: add support for `ftp://' protocol --- common/patterns.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'common/patterns.js') 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 !== ""); -- cgit v1.2.3