diff --git a/index.js b/index.js index 08fa329..21e53fe 100644 --- a/index.js +++ b/index.js @@ -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]) diff --git a/package.json b/package.json index 4594c3e..0aa7654 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/auth.js b/test/auth.js index 8393ab8..a65fa49 100644 --- a/test/auth.js +++ b/test/auth.js @@ -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') +}