Skip to content

Commit 2d0bb66

Browse files
committed
fix: Do not attempt to use url.URL when unavailable
Fix #61 This should not be ported to the latest branch, as Node.js v6 support was dropped there anyway. PR-URL: #62 Credit: @isaacs Close: #62 Reviewed-by: @isaacs
1 parent f2cdfcf commit 2d0bb66

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ function parseGitUrl (giturl) {
108108
var matched = giturl.match(/^([^@]+)@([^:/]+):[/]?((?:[^/]+[/])?[^/]+?)(?:[.]git)?(#.*)?$/)
109109
if (!matched) {
110110
var legacy = url.parse(giturl)
111-
if (legacy.auth) {
111+
// If we don't have url.URL, then sorry, this is just not fixable.
112+
// This affects Node <= 6.12.
113+
if (legacy.auth && typeof url.URL === 'function') {
112114
// git urls can be in the form of scp-style/ssh-connect strings, like
113115
// git+ssh://user@host.com:some/path, which the legacy url parser
114116
// supports, but WhatWG url.URL class does not. However, the legacy

test/auth.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,9 @@ tap.equal(parsedUrl.hostname, 'github.com')
1616
// For full backwards-compatibility; support auth where only username or only password is provided
1717
tap.equal(HostedGitInfo.fromUrl('https://user%3An%40me@github.com/npm/hosted-git-info.git').auth, 'user%3An%40me')
1818
tap.equal(HostedGitInfo.fromUrl('https://:p%40ss%3Aword@github.com/npm/hosted-git-info.git').auth, ':p%40ss%3Aword')
19+
20+
// don't try to url.URL parse it if url.URL is not available
21+
// 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')

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy