diff --git a/dist/index.js b/dist/index.js index 8b54fee..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@|https?:\/\/)([\w\.\-@]+)[\/:]([\~,\.\w,\-,\_,\/]+?(?:\.git|\/)?)$/; + const GIT_RE = /^(?:([a-z_][a-z0-9_-]{0,31})@|https?:\/\/)([\w\.\-@]+)[\/:]([\~,\.\w,\-,\_,\/]+?(?:\.git|\/)?)$/; const throwErr = msg => { const err = new Error(msg); @@ -77,10 +77,10 @@ const parseUrl = (url, normalize = false) => { if (matched) { parsed.protocols = ["ssh"]; parsed.protocol = "ssh"; - parsed.resource = matched[1]; - parsed.host = matched[1]; - parsed.user = "git"; - parsed.pathname = `/${matched[2]}`; + 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 40f37d6..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@|https?:\/\/)([\w\.\-@]+)[\/:]([\~,\.\w,\-,\_,\/]+?(?:\.git|\/)?)$/; + const GIT_RE = /^(?:([a-z_][a-z0-9_-]{0,31})@|https?:\/\/)([\w\.\-@]+)[\/:]([\~,\.\w,\-,\_,\/]+?(?:\.git|\/)?)$/; const throwErr = msg => { const err = new Error(msg); @@ -70,10 +70,10 @@ const parseUrl = (url, normalize = false) => { if (matched) { parsed.protocols = ["ssh"]; parsed.protocol = "ssh"; - parsed.resource = matched[1]; - parsed.host = matched[1]; - parsed.user = "git"; - parsed.pathname = `/${matched[2]}`; + 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 d7d9636..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@|https?:\/\/)([\w\.\-@]+)[\/:]([\~,\.\w,\-,\_,\/]+?(?:\.git|\/)?)$/ + const GIT_RE = /^(?:([a-z_][a-z0-9_-]{0,31})@|https?:\/\/)([\w\.\-@]+)[\/:]([\~,\.\w,\-,\_,\/]+?(?:\.git|\/)?)$/ const throwErr = msg => { const err = new Error(msg) @@ -69,10 +69,10 @@ const parseUrl = (url, normalize = false) => { if (matched) { parsed.protocols = ["ssh"] parsed.protocol = "ssh" - parsed.resource = matched[1] - parsed.host = matched[1] - parsed.user = "git" - parsed.pathname = `/${matched[2]}` + 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] , {