diff --git a/index.js b/index.js index b57880c..08fa329 100644 --- a/index.js +++ b/index.js @@ -108,7 +108,9 @@ function parseGitUrl (giturl) { var matched = giturl.match(/^([^@]+)@([^:/]+):[/]?((?:[^/]+[/])?[^/]+?)(?:[.]git)?(#.*)?$/) if (!matched) { var legacy = url.parse(giturl) - if (legacy.auth) { + // If we don't have url.URL, then sorry, this is just not fixable. + // This affects Node <= 6.12. + if (legacy.auth && typeof url.URL === 'function') { // git urls can be in the form of scp-style/ssh-connect strings, like // git+ssh://user@host.com:some/path, which the legacy url parser // supports, but WhatWG url.URL class does not. However, the legacy diff --git a/test/auth.js b/test/auth.js index 0e5c752..1fda1dd 100644 --- a/test/auth.js +++ b/test/auth.js @@ -16,3 +16,9 @@ tap.equal(parsedUrl.hostname, 'github.com') // For full backwards-compatibility; support auth where only username or only password is provided tap.equal(HostedGitInfo.fromUrl('https://user%3An%40me@github.com/npm/hosted-git-info.git').auth, 'user%3An%40me') tap.equal(HostedGitInfo.fromUrl('https://:p%40ss%3Aword@github.com/npm/hosted-git-info.git').auth, ':p%40ss%3Aword') + +// don't try to url.URL parse it if url.URL is not available +// ie, node <6.13. This is broken, but at least it doesn't throw. +url.URL = null +var parsedInfo = HostedGitInfo.fromUrl('https://user%3An%40me:p%40ss%3Aword@github.com/npm/xyz.git') +tap.equal(parsedInfo.auth, 'user:n@me:p@ss:word')