diff --git a/dist/index.js b/dist/index.js index 4c0f27e..2ed83b1 100755 --- a/dist/index.js +++ b/dist/index.js @@ -288,7 +288,7 @@ function normalizeUrl(urlString, options) { const parseUrl = (url, normalize = false) => { // Constants - const GIT_RE = /(^(git@|http(s)?:\/\/)([\w\.\-@]+)(\/|:))(([\~,\.\w,\-,\_,\/]+)(.git){0,1}((\/){0,1}))/; + const GIT_RE = /^(?:git@|https?:\/\/)([\w\.\-@]+)[\/:]([\~,\.\w,\-,\_,\/]+?(?:\.git|\/)?)$/; const throwErr = msg => { const err = new Error(msg); @@ -317,14 +317,15 @@ const parseUrl = (url, normalize = false) => { // Potential git-ssh urls if (parsed.parse_failed) { - const matched = parsed.href.match(GIT_RE); + const matched = parsed.href.match(GIT_RE); + if (matched) { parsed.protocols = ["ssh"]; parsed.protocol = "ssh"; - parsed.resource = matched[4]; - parsed.host = matched[4]; + parsed.resource = matched[1]; + parsed.host = matched[1]; parsed.user = "git"; - parsed.pathname = `/${matched[6]}`; + parsed.pathname = `/${matched[2]}`; parsed.parse_failed = false; } else { throwErr("URL parsing failed."); diff --git a/dist/index.mjs b/dist/index.mjs index f18c9e3..46f5bc6 100755 --- a/dist/index.mjs +++ b/dist/index.mjs @@ -282,7 +282,7 @@ function normalizeUrl(urlString, options) { const parseUrl = (url, normalize = false) => { // Constants - const GIT_RE = /(^(git@|http(s)?:\/\/)([\w\.\-@]+)(\/|:))(([\~,\.\w,\-,\_,\/]+)(.git){0,1}((\/){0,1}))/; + const GIT_RE = /^(?:git@|https?:\/\/)([\w\.\-@]+)[\/:]([\~,\.\w,\-,\_,\/]+?(?:\.git|\/)?)$/; const throwErr = msg => { const err = new Error(msg); @@ -311,14 +311,15 @@ const parseUrl = (url, normalize = false) => { // Potential git-ssh urls if (parsed.parse_failed) { - const matched = parsed.href.match(GIT_RE); + const matched = parsed.href.match(GIT_RE); + if (matched) { parsed.protocols = ["ssh"]; parsed.protocol = "ssh"; - parsed.resource = matched[4]; - parsed.host = matched[4]; + parsed.resource = matched[1]; + parsed.host = matched[1]; parsed.user = "git"; - parsed.pathname = `/${matched[6]}`; + parsed.pathname = `/${matched[2]}`; parsed.parse_failed = false; } else { throwErr("URL parsing failed."); diff --git a/src/index.js b/src/index.js index 3981b89..d7d9636 100644 --- a/src/index.js +++ b/src/index.js @@ -35,7 +35,7 @@ import normalizeUrl from "normalize-url"; const parseUrl = (url, normalize = false) => { // Constants - const GIT_RE = /(^(git@|http(s)?:\/\/)([\w\.\-@]+)(\/|:))(([\~,\.\w,\-,\_,\/]+)(.git){0,1}((\/){0,1}))/ + const GIT_RE = /^(?:git@|https?:\/\/)([\w\.\-@]+)[\/:]([\~,\.\w,\-,\_,\/]+?(?:\.git|\/)?)$/ const throwErr = msg => { const err = new Error(msg) @@ -64,14 +64,15 @@ const parseUrl = (url, normalize = false) => { // Potential git-ssh urls if (parsed.parse_failed) { - const matched = parsed.href.match(GIT_RE) + const matched = parsed.href.match(GIT_RE) + if (matched) { parsed.protocols = ["ssh"] parsed.protocol = "ssh" - parsed.resource = matched[4] - parsed.host = matched[4] + parsed.resource = matched[1] + parsed.host = matched[1] parsed.user = "git" - parsed.pathname = `/${matched[6]}` + parsed.pathname = `/${matched[2]}` parsed.parse_failed = false } else { throwErr("URL parsing failed.")