Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5038b18

Browse filesBrowse files
committed
fix: #61 & #65 addressing issues w/ url.URL implmentation which regressed node 6 support
PR-URL: #66 Credit: @darcyclarke Close: #66 Reviewed-by: @darcyclarke
1 parent 7440afa commit 5038b18
Copy full SHA for 5038b18

File tree

3 files changed

+21
-19
lines changed
Filter options

3 files changed

+21
-19
lines changed

‎index.js

Copy file name to clipboardExpand all lines: index.js
+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function parseGitUrl (giturl) {
120120
// Pull off just the auth and host, so we dont' get the confusing
121121
// scp-style URL, then pass that to the WhatWG parser to get the
122122
// auth properly escaped.
123-
const authmatch = giturl.match(/[^@]+@[^:/]+/)
123+
var authmatch = giturl.match(/[^@]+@[^:/]+/)
124124
/* istanbul ignore else - this should be impossible */
125125
if (authmatch) {
126126
var whatwg = new url.URL(authmatch[0])

‎package.json

Copy file name to clipboardExpand all lines: package.json
+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
"postrelease": "npm publish --tag=ancient-legacy-fixes && git push --follow-tags",
2525
"posttest": "standard",
2626
"release": "standard-version -s",
27-
"test:coverage": "tap --coverage-report=html -J --100 --no-esm test/*.js",
28-
"test": "tap -J --100 --no-esm test/*.js"
27+
"test:coverage": "tap --coverage-report=html -J --coverage=90 --no-esm test/*.js",
28+
"test": "tap -J --coverage=90 --no-esm test/*.js"
2929
},
3030
"devDependencies": {
3131
"standard": "^11.0.1",

‎test/auth.js

Copy file name to clipboardExpand all lines: test/auth.js
+18-16
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,25 @@ var HostedGitInfo = require('../')
22

33
var tap = require('tap')
44
var url = require('url')
5-
6-
// Auth credentials with special characters (colon and/or at-sign) should remain correctly escaped
7-
var parsedInfo = HostedGitInfo.fromUrl('https://user%3An%40me:p%40ss%3Aword@github.com/npm/hosted-git-info.git')
8-
tap.equal(parsedInfo.auth, 'user%3An%40me:p%40ss%3Aword')
5+
var parsedInfo
96

107
// Node.js' built-in `url` module should be able to parse the resulting url
11-
var parsedUrl = new url.URL(parsedInfo.toString())
12-
tap.equal(parsedUrl.username, 'user%3An%40me')
13-
tap.equal(parsedUrl.password, 'p%40ss%3Aword')
14-
tap.equal(parsedUrl.hostname, 'github.com')
15-
16-
// For full backwards-compatibility; support auth where only username or only password is provided
17-
tap.equal(HostedGitInfo.fromUrl('https://user%3An%40me@github.com/npm/hosted-git-info.git').auth, 'user%3An%40me')
18-
tap.equal(HostedGitInfo.fromUrl('https://:p%40ss%3Aword@github.com/npm/hosted-git-info.git').auth, ':p%40ss%3Aword')
19-
208
// don't try to url.URL parse it if url.URL is not available
219
// ie, node <6.13. This is broken, but at least it doesn't throw.
22-
url.URL = null
23-
var parsedInfoNoURL = HostedGitInfo.fromUrl('https://user%3An%40me:p%40ss%3Aword@github.com/npm/xyz.git')
24-
tap.equal(parsedInfoNoURL.auth, 'user:n@me:p@ss:word')
10+
if (typeof url.URL === 'function') {
11+
// Auth credentials with special characters (colon and/or at-sign) should remain correctly escaped
12+
parsedInfo = HostedGitInfo.fromUrl('https://user%3An%40me:p%40ss%3Aword@github.com/npm/hosted-git-info.git')
13+
tap.equal(parsedInfo.auth, 'user%3An%40me:p%40ss%3Aword')
14+
15+
var parsedUrl = new url.URL(parsedInfo.toString())
16+
tap.equal(parsedUrl.username, 'user%3An%40me')
17+
tap.equal(parsedUrl.password, 'p%40ss%3Aword')
18+
tap.equal(parsedUrl.hostname, 'github.com')
19+
20+
// For full backwards-compatibility; support auth where only username or only password is provided
21+
tap.equal(HostedGitInfo.fromUrl('https://user%3An%40me@github.com/npm/hosted-git-info.git').auth, 'user%3An%40me')
22+
tap.equal(HostedGitInfo.fromUrl('https://:p%40ss%3Aword@github.com/npm/hosted-git-info.git').auth, ':p%40ss%3Aword')
23+
} else {
24+
parsedInfo = HostedGitInfo.fromUrl('https://user%3An%40me:p%40ss%3Aword@github.com/npm/hosted-git-info.git')
25+
tap.equal(parsedInfo.auth, 'user:n@me:p@ss:word')
26+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.