-
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.
Ensure passwords in hosted Git URLs are correctly escaped
PR-URL: #58 Credit: @stevenhilder Close: #58 Reviewed-by: @darcyclarke
- Loading branch information
1 parent
624fd6f
commit ff259a6
Showing
2 changed files
with
28 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
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%3Aword@github.com/npm/hosted-git-info.git') | ||
tap.equal(parsedInfo.auth, 'user%3An%40me:p%40ss%3Aword') | ||
|
||
// 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%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') |
This will broken old versions of Node v6, If we still support Node v6
hosted-git-info/.travis.yml
Line 7 in ff259a6
We should use https://github.com/jsdom/whatwg-url on Node v6.