Skip to content

Commit 2dedc7b

Browse files
committed
fix: do not use url.URL to support early node 6 and scp-style URLs
fix npm#60 and npm#61
1 parent e1b83df commit 2dedc7b

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

index.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,8 @@ function parseGitUrl (giturl) {
109109
if (!matched) {
110110
var legacy = url.parse(giturl)
111111
if (legacy.auth) {
112-
var whatwg = new url.URL(giturl)
113-
legacy.auth = whatwg.username || ''
114-
if (whatwg.password) legacy.auth += ':' + whatwg.password
112+
// Replace the url decoded username:password with the url encoded username:password from the original url
113+
legacy.auth = giturl.match(new RegExp('^[^/]+//([^@]+)@'))[1]
115114
}
116115
return legacy
117116
}

test/auth.js

-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
var HostedGitInfo = require('../')
22

33
var tap = require('tap')
4-
var url = require('url')
54

65
// Auth credentials with special characters (colon and/or at-sign) should remain correctly escaped
76
var parsedInfo = HostedGitInfo.fromUrl('https://user%3An%40me:p%40ss%[email protected]/npm/hosted-git-info.git')
87
tap.equal(parsedInfo.auth, 'user%3An%40me:p%40ss%3Aword')
98

10-
// Node.js' built-in `url` module should be able to parse the resulting url
11-
var parsedUrl = new url.URL(parsedInfo.toString())
12-
tap.equal(parsedUrl.username, 'user%3An%40me')
13-
tap.equal(parsedUrl.password, 'p%40ss%3Aword')
14-
tap.equal(parsedUrl.hostname, 'github.com')
15-
169
// For full backwards-compatibility; support auth where only username or only password is provided
1710
tap.equal(HostedGitInfo.fromUrl('https://user%3An%[email protected]/npm/hosted-git-info.git').auth, 'user%3An%40me')
1811
tap.equal(HostedGitInfo.fromUrl('https://:p%40ss%[email protected]/npm/hosted-git-info.git').auth, ':p%40ss%3Aword')

test/basic.js

+3
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ test('basic', function (t) {
3535
t.is(HostedGit.fromUrl(), undefined, 'no value is not hosted')
3636
t.is(HostedGit.fromUrl('git+file:///foo/bar'), undefined, 'url that has no host')
3737
t.is(HostedGit.fromUrl('github.com/abc/def/'), undefined, 'forgot the protocol')
38+
t.is(HostedGit.fromUrl('//github.com/abc/def/'), undefined, 'forgot the protocol')
3839
t.is(HostedGit.fromUrl('completely-invalid'), undefined, 'not a url is not hosted')
3940

41+
t.is(HostedGit.fromUrl('git+ssh://[email protected]:RND/electron-tools/some-tool#2.0.1'), undefined, 'properly ignores non-hosted scp style urls')
42+
4043
t.is(HostedGit.fromUrl('http://github.com/foo/bar').toString(), 'git+ssh://[email protected]/foo/bar.git', 'github http protocol use git+ssh urls')
4144
t.end()
4245
})

0 commit comments

Comments
 (0)