diff --git a/dist/index.js b/dist/index.js index d9100ec..7bf5818 100755 --- a/dist/index.js +++ b/dist/index.js @@ -43,7 +43,7 @@ var normalizeUrl__default = /*#__PURE__*/_interopDefaultLegacy(normalizeUrl); const parseUrl = (url, normalize = false) => { // Constants - const GIT_RE = /(^(git@|http(s)?:\/\/)([\w\.\-@]+)(\/|:))(([\~,\.\w,\-,\_,\/]+)(.git){0,1}((\/){0,1}))/; + const GIT_RE = /^(?:([a-z_][a-z0-9_-]{0,31})@|https?:\/\/)([\w\.\-@]+)[\/:]([\~,\.\w,\-,\_,\/]+?(?:\.git|\/)?)$/; const throwErr = msg => { const err = new Error(msg); @@ -72,14 +72,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.user = "git"; - parsed.pathname = `/${matched[6]}`; + parsed.resource = matched[2]; + parsed.host = matched[2]; + parsed.user = matched[1]; + parsed.pathname = `/${matched[3]}`; parsed.parse_failed = false; } else { throwErr("URL parsing failed."); diff --git a/dist/index.mjs b/dist/index.mjs index 0e255fd..eea37a1 100755 --- a/dist/index.mjs +++ b/dist/index.mjs @@ -36,7 +36,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 = /^(?:([a-z_][a-z0-9_-]{0,31})@|https?:\/\/)([\w\.\-@]+)[\/:]([\~,\.\w,\-,\_,\/]+?(?:\.git|\/)?)$/; const throwErr = msg => { const err = new Error(msg); @@ -65,14 +65,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.user = "git"; - parsed.pathname = `/${matched[6]}`; + parsed.resource = matched[2]; + parsed.host = matched[2]; + parsed.user = matched[1]; + parsed.pathname = `/${matched[3]}`; parsed.parse_failed = false; } else { throwErr("URL parsing failed."); diff --git a/src/index.js b/src/index.js index 3981b89..b165cc7 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 = /^(?:([a-z_][a-z0-9_-]{0,31})@|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.user = "git" - parsed.pathname = `/${matched[6]}` + parsed.resource = matched[2] + parsed.host = matched[2] + parsed.user = matched[1] + parsed.pathname = `/${matched[3]}` parsed.parse_failed = false } else { throwErr("URL parsing failed.") diff --git a/test/index.mjs b/test/index.mjs index 7b484ba..5c76aeb 100644 --- a/test/index.mjs +++ b/test/index.mjs @@ -133,6 +133,23 @@ const INPUTS = [ , parse_failed: false } ] + , [ + ["org-12345678@github.my-enterprise.com:my-org/my-repo.git", false], + { + protocols: [ 'ssh' ] + , protocol: 'ssh' + , port: '' + , resource: 'github.my-enterprise.com' + , host: 'github.my-enterprise.com' + , user: 'org-12345678' + , password: '' + , pathname: '/my-org/my-repo.git' + , hash: '' + , search: '' + , query: {} + , parse_failed: false + } + ] , [ ["git@github.com:halup/Cloud.API.Gateway.git", false] , {