Skip to content

Commit c931482

Browse files
Erveoniarna
authored andcommitted
fix(parse): Crash on strings that parse to having no host
Fixes: #35
1 parent b7b18a9 commit c931482

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function fromUrl (giturl, opts) {
5858
project = decodeURIComponent(shortcutMatch[3])
5959
defaultRepresentation = 'shortcut'
6060
} else {
61-
if (parsed.host !== gitHostInfo.domain && parsed.host.replace(/^www[.]/, '') !== gitHostInfo.domain) return
61+
if (parsed.host && parsed.host !== gitHostInfo.domain && parsed.host.replace(/^www[.]/, '') !== gitHostInfo.domain) return
6262
if (!gitHostInfo.protocols_re.test(parsed.protocol)) return
6363
if (!parsed.path) return
6464
var pathmatch = gitHostInfo.pathmatch

test/basic.js

+7
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,12 @@ test('basic', function (t) {
2525
t.is(HostedGit.fromUrl('gist:123').https(), 'git+https://gist.github.com/123.git', 'non-user shortcut')
2626

2727
t.is(HostedGit.fromUrl('git+https://github.com:foo/repo.git#master').https(), 'git+https://github.com/foo/repo.git#master', 'scp style urls are upgraded')
28+
29+
t.is(HostedGit.fromUrl(''), undefined, 'empty strings are not hosted')
30+
t.is(HostedGit.fromUrl(null), undefined, 'null is not hosted')
31+
t.is(HostedGit.fromUrl(), undefined, 'no value is not hosted')
32+
t.is(HostedGit.fromUrl('git+file:///foo/bar'), undefined, 'url that has no host')
33+
t.is(HostedGit.fromUrl('github.com/abc/def/'), undefined, 'forgot the protocol')
34+
t.is(HostedGit.fromUrl('completely-invalid'), undefined, 'not a url is not hosted')
2835
t.end()
2936
})

0 commit comments

Comments
 (0)