diff --git a/__tests__/util/git.js b/__tests__/util/git.js index 20bcb556fd..a2240f6e53 100644 --- a/__tests__/util/git.js +++ b/__tests__/util/git.js @@ -24,6 +24,12 @@ test('npmUrlToGitUrl', () => { hostname: 'github.com', repository: 'git://github.com/npm-opam/ocamlfind.git', }); + expect(Git.npmUrlToGitUrl('git+ssh://git@gitlab.mydomain.tld:10202/project-name/my-package.git')) + .toEqual({ + protocol: 'ssh:', + hostname: 'gitlab.mydomain.tld', + repository: 'ssh://git@gitlab.mydomain.tld:10202/project-name/my-package.git', + }); expect(Git.npmUrlToGitUrl('git+ssh://git@github.com/npm-opam/ocamlfind.git')) .toEqual({ protocol: 'ssh:', diff --git a/src/util/git.js b/src/util/git.js index d388972a59..e666dd2f8d 100644 --- a/src/util/git.js +++ b/src/util/git.js @@ -58,9 +58,11 @@ export default class Git { */ static npmUrlToGitUrl(npmUrl: string): GitUrl { // Special case in npm, where ssh:// prefix is stripped to pass scp-like syntax - // which works as remote path only if there are no slashes before ':' - const match = npmUrl.match(/^git\+ssh:\/\/((?:[^@:\/]+@)?([^@:\/]+):.*)/); - if (match) { + // which in git works as remote path only if there are no slashes before ':'. + const match = npmUrl.match(/^git\+ssh:\/\/((?:[^@:\/]+@)?([^@:\/]+):([^/]*).*)/); + // Additionally, if the host part is digits-only, npm falls back to + // interpreting it as an SSH URL with a port number. + if (match && /[^0-9]/.test(match[3])) { return { protocol: 'ssh:', hostname: match[2],