Skip to content

Commit c91490e

Browse files
fix: correctProtocol misparsing protocol (#314)
Fixes: #315
1 parent bc22025 commit c91490e

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

lib/parse-url.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,23 @@ const correctProtocol = (arg, protocols) => {
2121
return arg
2222
}
2323

24+
if (arg.substr(firstColon, 3) === '://') {
25+
// If arg is given as <foo>://<bar>, then this is already a valid URL.
26+
return arg
27+
}
28+
2429
const firstAt = arg.indexOf('@')
2530
if (firstAt > -1) {
2631
if (firstAt > firstColon) {
32+
// URL has the form of <foo>:<bar>@<baz>. Assume this is a git+ssh URL.
2733
return `git+ssh://${arg}`
2834
} else {
35+
// URL has the form 'git@github.com:npm/hosted-git-info.git'.
2936
return arg
3037
}
3138
}
3239

33-
const doubleSlash = arg.indexOf('//')
34-
if (doubleSlash === firstColon + 1) {
35-
return arg
36-
}
37-
40+
// Correct <foo>:<bar> to <foo>://<bar>
3841
return `${arg.slice(0, firstColon + 1)}//${arg.slice(firstColon + 1)}`
3942
}
4043

test/parse-url.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,10 @@ t.test('can parse file urls', async t => {
1515
t.ok(parseUrl(u))
1616
t.ok(HostedGit.parseUrl(u))
1717
})
18+
19+
t.test('can parse custom urls', async t => {
20+
const u = 'foobar://user:host@path'
21+
t.ok(parseUrl(u, {}))
22+
t.equal(parseUrl(u, {}).protocol, 'foobar:')
23+
t.ok(HostedGit.parseUrl(u))
24+
})

0 commit comments

Comments
 (0)