diff --git a/dist/index.js b/dist/index.js index 2ed83b1..111a11a 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@|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); @@ -322,10 +322,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 46f5bc6..4fd7be5 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@|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); @@ -316,10 +316,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 0bb6ead..90b04b0 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] , {