Skip to content

Commit f24575d

Browse files
committed
fix: 61 & 65 issues w/ url.URL implmentation
1 parent 7440afa commit f24575d

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

Diff for: 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])

Diff for: test/auth.js

+17-16
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@ var HostedGitInfo = require('../')
33
var tap = require('tap')
44
var url = require('url')
55

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%[email protected]/npm/hosted-git-info.git')
8-
tap.equal(parsedInfo.auth, 'user%3An%40me:p%40ss%3Aword')
9-
106
// 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%[email protected]/npm/hosted-git-info.git').auth, 'user%3An%40me')
18-
tap.equal(HostedGitInfo.fromUrl('https://:p%40ss%[email protected]/npm/hosted-git-info.git').auth, ':p%40ss%3Aword')
19-
207
// don't try to url.URL parse it if url.URL is not available
218
// 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%[email protected]/npm/xyz.git')
24-
tap.equal(parsedInfoNoURL.auth, 'user:n@me:p@ss:word')
9+
if (typeof url.URL === 'function') {
10+
// Auth credentials with special characters (colon and/or at-sign) should remain correctly escaped
11+
var parsedInfo = HostedGitInfo.fromUrl('https://user%3An%40me:p%40ss%[email protected]/npm/hosted-git-info.git')
12+
tap.equal(parsedInfo.auth, 'user%3An%40me:p%40ss%3Aword')
13+
14+
var parsedUrl = new url.URL(parsedInfo.toString())
15+
tap.equal(parsedUrl.username, 'user%3An%40me')
16+
tap.equal(parsedUrl.password, 'p%40ss%3Aword')
17+
tap.equal(parsedUrl.hostname, 'github.com')
18+
19+
// For full backwards-compatibility; support auth where only username or only password is provided
20+
tap.equal(HostedGitInfo.fromUrl('https://user%3An%[email protected]/npm/hosted-git-info.git').auth, 'user%3An%40me')
21+
tap.equal(HostedGitInfo.fromUrl('https://:p%40ss%[email protected]/npm/hosted-git-info.git').auth, ':p%40ss%3Aword')
22+
} else {
23+
var parsedInfoNoURL = HostedGitInfo.fromUrl('https://user%3An%40me:p%40ss%[email protected]/npm/xyz.git')
24+
tap.equal(parsedInfoNoURL.auth, 'user:n@me:p@ss:word')
25+
}

0 commit comments

Comments
 (0)