-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…ssed node 6 support PR-URL: #66 Credit: @darcyclarke Close: #66 Reviewed-by: @darcyclarke
- Loading branch information
1 parent
7440afa
commit 5038b18
Showing
3 changed files
with
21 additions
and
19 deletions.
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
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
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 |
---|---|---|
|
@@ -2,23 +2,25 @@ var HostedGitInfo = require('../') | |
|
||
var tap = require('tap') | ||
var url = require('url') | ||
|
||
// Auth credentials with special characters (colon and/or at-sign) should remain correctly escaped | ||
var parsedInfo = HostedGitInfo.fromUrl('https://user%3An%40me:p%40ss%[email protected]/npm/hosted-git-info.git') | ||
tap.equal(parsedInfo.auth, 'user%3An%40me:p%40ss%3Aword') | ||
var parsedInfo | ||
|
||
// Node.js' built-in `url` module should be able to parse the resulting url | ||
var parsedUrl = new url.URL(parsedInfo.toString()) | ||
tap.equal(parsedUrl.username, 'user%3An%40me') | ||
tap.equal(parsedUrl.password, 'p%40ss%3Aword') | ||
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') | ||
if (typeof url.URL === 'function') { | ||
// Auth credentials with special characters (colon and/or at-sign) should remain correctly escaped | ||
parsedInfo = HostedGitInfo.fromUrl('https://user%3An%40me:p%40ss%[email protected]/npm/hosted-git-info.git') | ||
tap.equal(parsedInfo.auth, 'user%3An%40me:p%40ss%3Aword') | ||
|
||
var parsedUrl = new url.URL(parsedInfo.toString()) | ||
tap.equal(parsedUrl.username, 'user%3An%40me') | ||
tap.equal(parsedUrl.password, 'p%40ss%3Aword') | ||
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') | ||
} else { | ||
parsedInfo = HostedGitInfo.fromUrl('https://user%3An%40me:p%40ss%[email protected]/npm/hosted-git-info.git') | ||
tap.equal(parsedInfo.auth, 'user:n@me:p@ss:word') | ||
} |