From 3b1d6298d60bd0b7dcb194da30f1475c72babe05 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Mon, 5 Aug 2019 10:50:16 +0800 Subject: [PATCH] fix: http protocol use sshurl by default PR-URL: https://github.com/npm/hosted-git-info/pull/48 Credit: @fengmk2 Close: #48 Reviewed-by: @isaacs --- git-host.js | 4 ++-- test/basic.js | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/git-host.js b/git-host.js index 0102727..ee5bb1a 100644 --- a/git-host.js +++ b/git-host.js @@ -151,6 +151,6 @@ GitHost.prototype.getDefaultRepresentation = function () { } GitHost.prototype.toString = function (opts) { - const method = this.default || /* istanbul ignore next */ 'sshurl' - return this[method](opts) + if (this.default && typeof this[this.default] === 'function') return this[this.default](opts) + return this.sshurl(opts) } diff --git a/test/basic.js b/test/basic.js index e2c6bdc..22c0bda 100644 --- a/test/basic.js +++ b/test/basic.js @@ -35,5 +35,7 @@ test('basic', function (t) { t.is(HostedGit.fromUrl('git+file:///foo/bar'), undefined, 'url that has no host') t.is(HostedGit.fromUrl('github.com/abc/def/'), undefined, 'forgot the protocol') t.is(HostedGit.fromUrl('completely-invalid'), undefined, 'not a url is not hosted') + + t.is(HostedGit.fromUrl('http://github.com/foo/bar').toString(), 'git+ssh://git@github.com/foo/bar.git', 'github http protocol use git+ssh urls') t.end() })