Skip to content

Navigation Menu

Sign in
Appearance settings

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 5b192c8

Browse filesBrowse files
committed
fix: #61 & #65 addressing issues w/ url.URL implmentation which regressed node 6 support
1 parent 7440afa commit 5b192c8
Copy full SHA for 5b192c8

File tree

Expand file treeCollapse file tree

2 files changed

+18
-17
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+18
-17
lines changed

‎index.js

Copy file name to clipboardExpand all lines: index.js
+1-1Lines changed: 1 addition & 1 deletion
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])

‎test/auth.js

Copy file name to clipboardExpand all lines: test/auth.js
+17-16Lines changed: 17 additions & 16 deletions
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%3Aword@github.com/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%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-
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%3Aword@github.com/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%3Aword@github.com/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%40me@github.com/npm/hosted-git-info.git').auth, 'user%3An%40me')
21+
tap.equal(HostedGitInfo.fromUrl('https://:p%40ss%3Aword@github.com/npm/hosted-git-info.git').auth, ':p%40ss%3Aword')
22+
} else {
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')
25+
}

0 commit comments

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