Skip to content

Commit 6dd1003

Browse files
committed
fix: correctProtocol misparsing protocol
1 parent 97fef20 commit 6dd1003

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lib/parse-url.js

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

24+
const doubleSlash = arg.indexOf('//')
25+
if (doubleSlash === firstColon + 1) {
26+
return arg
27+
}
28+
2429
const firstAt = arg.indexOf('@')
2530
if (firstAt > -1) {
2631
if (firstAt > firstColon) {
@@ -30,11 +35,6 @@ const correctProtocol = (arg, protocols) => {
3035
}
3136
}
3237

33-
const doubleSlash = arg.indexOf('//')
34-
if (doubleSlash === firstColon + 1) {
35-
return arg
36-
}
37-
3838
return `${arg.slice(0, firstColon + 1)}//${arg.slice(firstColon + 1)}`
3939
}
4040

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://baz.com:user/repo'
21+
t.ok(parseUrl(u))
22+
t.equal(parseUrl(u).protocol, 'foobar:')
23+
t.ok(HostedGit.parseUrl(u))
24+
})

0 commit comments

Comments
 (0)