diff --git a/lib/parse-url.js b/lib/parse-url.js index 7d5489c..bfd54b9 100644 --- a/lib/parse-url.js +++ b/lib/parse-url.js @@ -21,20 +21,23 @@ const correctProtocol = (arg, protocols) => { return arg } + if (arg.substr(firstColon, 3) === '://') { + // If arg is given as ://, then this is already a valid URL. + return arg + } + const firstAt = arg.indexOf('@') if (firstAt > -1) { if (firstAt > firstColon) { + // URL has the form of :@. Assume this is a git+ssh URL. return `git+ssh://${arg}` } else { + // URL has the form 'git@github.com:npm/hosted-git-info.git'. return arg } } - const doubleSlash = arg.indexOf('//') - if (doubleSlash === firstColon + 1) { - return arg - } - + // Correct : to :// return `${arg.slice(0, firstColon + 1)}//${arg.slice(firstColon + 1)}` } diff --git a/test/parse-url.js b/test/parse-url.js index 54e7d16..70f04b1 100644 --- a/test/parse-url.js +++ b/test/parse-url.js @@ -15,3 +15,10 @@ t.test('can parse file urls', async t => { t.ok(parseUrl(u)) t.ok(HostedGit.parseUrl(u)) }) + +t.test('can parse custom urls', async t => { + const u = 'foobar://user:host@path' + t.ok(parseUrl(u, {})) + t.equal(parseUrl(u, {}).protocol, 'foobar:') + t.ok(HostedGit.parseUrl(u)) +})