Skip to content

Commit

Permalink
Better match npm's SCP vs SSH URL heuristic
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Apr 14, 2017
1 parent 4cdc520 commit 31e1905
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 6 additions & 0 deletions __tests__/util/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ test('npmUrlToGitUrl', () => {
hostname: 'github.com',
repository: 'git://github.com/npm-opam/ocamlfind.git',
});
expect(Git.npmUrlToGitUrl('git+ssh://[email protected]:10202/project-name/my-package.git'))
.toEqual({
protocol: 'ssh:',
hostname: 'gitlab.mydomain.tld',
repository: 'ssh://[email protected]:10202/project-name/my-package.git',
});
expect(Git.npmUrlToGitUrl('git+ssh://[email protected]/npm-opam/ocamlfind.git'))
.toEqual({
protocol: 'ssh:',
Expand Down
8 changes: 5 additions & 3 deletions src/util/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down

0 comments on commit 31e1905

Please sign in to comment.