fix: Do not attempt to use url.URL when unavailable · npm/hosted-git-info@2d0bb66 (original) (raw)
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -108,7 +108,9 @@ function parseGitUrl (giturl) { | ||
| 108 | 108 | var matched = giturl.match(/^([^@]+)@([^:/]+):[/]?((?:[^/]+[/])?[^/]+?)(?:[.]git)?(#.*)?$/) |
| 109 | 109 | if (!matched) { |
| 110 | 110 | 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') { | |
| 112 | 114 | // git urls can be in the form of scp-style/ssh-connect strings, like |
| 113 | 115 | // git+ssh://user@host.com:some/path, which the legacy url parser |
| 114 | 116 | // supports, but WhatWG url.URL class does not. However, the legacy |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -16,3 +16,9 @@ tap.equal(parsedUrl.hostname, 'github.com') | ||
| 16 | 16 | // For full backwards-compatibility; support auth where only username or only password is provided |
| 17 | 17 | tap.equal(HostedGitInfo.fromUrl('https://user%3An%40me@github.com/npm/hosted-git-info.git').auth, 'user%3An%40me') |
| 18 | 18 | 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') |