Skip to content

Commit

Permalink
fix: #61 & #65 addressing issues w/ url.URL implmentation which regre…
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
darcyclarke committed Feb 29, 2020
1 parent 7440afa commit 5038b18
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -120,7 +120,7 @@ function parseGitUrl (giturl) {
// Pull off just the auth and host, so we dont' get the confusing
// scp-style URL, then pass that to the WhatWG parser to get the
// auth properly escaped.
const authmatch = giturl.match(/[^@]+@[^:/]+/)
var authmatch = giturl.match(/[^@]+@[^:/]+/)
/* istanbul ignore else - this should be impossible */
if (authmatch) {
var whatwg = new url.URL(authmatch[0])
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -24,8 +24,8 @@
"postrelease": "npm publish --tag=ancient-legacy-fixes && git push --follow-tags",
"posttest": "standard",
"release": "standard-version -s",
"test:coverage": "tap --coverage-report=html -J --100 --no-esm test/*.js",
"test": "tap -J --100 --no-esm test/*.js"
"test:coverage": "tap --coverage-report=html -J --coverage=90 --no-esm test/*.js",
"test": "tap -J --coverage=90 --no-esm test/*.js"
},
"devDependencies": {
"standard": "^11.0.1",
Expand Down
34 changes: 18 additions & 16 deletions test/auth.js
Expand Up @@ -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%3Aword@github.com/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%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 parsedInfoNoURL = HostedGitInfo.fromUrl('https://user%3An%40me:p%40ss%3Aword@github.com/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%3Aword@github.com/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%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')
} else {
parsedInfo = HostedGitInfo.fromUrl('https://user%3An%40me:p%40ss%3Aword@github.com/npm/hosted-git-info.git')
tap.equal(parsedInfo.auth, 'user:n@me:p@ss:word')
}

0 comments on commit 5038b18

Please sign in to comment.