-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
2 changed files
with
9 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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://[email protected]:some/path, which the legacy url parser | ||
// supports, but WhatWG url.URL class does not. However, the legacy | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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%[email protected]/npm/hosted-git-info.git').auth, 'user%3An%40me') | ||
tap.equal(HostedGitInfo.fromUrl('https://:p%40ss%[email protected]/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 parsedInfoNoURL = HostedGitInfo.fromUrl('https://user%3An%40me:p%40ss%[email protected]/npm/xyz.git') | ||
tap.equal(parsedInfoNoURL.auth, 'user:n@me:p@ss:word') |