Skip to content

Commit 2d0bb66

Browse files
committed
fix: Do not attempt to use url.URL when unavailable
Fix #61 This should not be ported to the latest branch, as Node.js v6 support was dropped there anyway. PR-URL: #62 Credit: @isaacs Close: #62 Reviewed-by: @isaacs
1 parent f2cdfcf commit 2d0bb66

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ function parseGitUrl (giturl) {
108108
var matched = giturl.match(/^([^@]+)@([^:/]+):[/]?((?:[^/]+[/])?[^/]+?)(?:[.]git)?(#.*)?$/)
109109
if (!matched) {
110110
var legacy = url.parse(giturl)
111-
if (legacy.auth) {
111+
// If we don't have url.URL, then sorry, this is just not fixable.
112+
// This affects Node <= 6.12.
113+
if (legacy.auth && typeof url.URL === 'function') {
112114
// git urls can be in the form of scp-style/ssh-connect strings, like
113115
// git+ssh://user@host.com:some/path, which the legacy url parser
114116
// supports, but WhatWG url.URL class does not. However, the legacy

test/auth.js

+6
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,9 @@ tap.equal(parsedUrl.hostname, 'github.com')
1616
// For full backwards-compatibility; support auth where only username or only password is provided
1717
tap.equal(HostedGitInfo.fromUrl('https://user%3An%40me@github.com/npm/hosted-git-info.git').auth, 'user%3An%40me')
1818
tap.equal(HostedGitInfo.fromUrl('https://:p%40ss%3Aword@github.com/npm/hosted-git-info.git').auth, ':p%40ss%3Aword')
19+
20+
// don't try to url.URL parse it if url.URL is not available
21+
// ie, node <6.13. This is broken, but at least it doesn't throw.
22+
url.URL = null
23+
var parsedInfoNoURL = HostedGitInfo.fromUrl('https://user%3An%40me:p%40ss%3Aword@github.com/npm/xyz.git')
24+
tap.equal(parsedInfoNoURL.auth, 'user:n@me:p@ss:word')

0 commit comments

Comments
 (0)