fix: #61 & #65 addressing issues w/ url.URL implmentation which regre… · npm/hosted-git-info@5038b18 (original) (raw)
`@@ -2,23 +2,25 @@ var HostedGitInfo = require('../')
`
2
2
``
3
3
`var tap = require('tap')
`
4
4
`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
`
9
6
``
10
7
`` // 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
``
-
20
8
`// don't try to url.URL parse it if url.URL is not available
`
21
9
`// 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
`+
}
`