fix: Do not attempt to use url.URL when unavailable · npm/hosted-git-info@2d0bb66

2 files changed

lines changed

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

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')