Skip to content

Commit 3e5fbec

Browse files
committedOct 8, 2019
fix: do not encodeURIComponent the domain
I ran into a situation where I have to test how Pacote handles git shorthands from hosted-git-info, but I didn't want to ping GitHub to run my tests. I set up a git daemon and http server on localhost easily enough, but it was still necessary to make it a 'real' HostedGit for the purposes of npm-package-arg, and the : with port number was getting URL encoded. This shows an example of doing this hack/test workaround, and fixes the encoding issue. It would be interesting to perhaps support GitHub Enterprise or on-prem GitLab by letting users specify a prefix and format for hosted git info in their npm configs, and then clone the definition with a different domain name. PR-URL: #53 Credit: @isaacs Close: #53 Reviewed-by: @isaacs
1 parent 97c8caa commit 3e5fbec

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed
 

‎git-host.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ GitHost.prototype._fill = function (template, opts) {
5656
vars[key] = value.split('/').map(function (pathComponent) {
5757
return encodeURIComponent(pathComponent)
5858
}).join('/')
59-
} else {
59+
} else if (key !== 'domain') {
6060
vars[key] = encodeURIComponent(value)
6161
}
6262
})

‎test/localhost.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// An example of a custom setup, useful when testing modules like pacote,
2+
// which do various things with these git shortcuts.
3+
const t = require('tap')
4+
const ghi = require('../git-host-info.js')
5+
ghi.localhost = {
6+
protocols: [ 'git' ],
7+
domain: 'localhost:12345',
8+
gittemplate: 'git://{domain}/{user}{#committish}',
9+
treepath: 'not-implemented',
10+
tarballtemplate: 'http://localhost:18000/repo-HEAD.tgz',
11+
shortcuttemplate: '{type}:{user}/x{#committish}',
12+
pathtemplate: '/{user}{#committish}',
13+
pathmatch: /^\/(repo|submodule-repo)/,
14+
hashformat: h => h,
15+
protocols_re: /^(git):$/
16+
}
17+
18+
const gh = require('../')
19+
const f = gh.fromUrl('git://localhost:12345/repo')
20+
21+
t.ok(f, 'got a localhost "hosted" repo')
22+
t.equal(f.git(), 'git://localhost:12345/repo')
23+
t.equal(f.tarball(), 'http://localhost:18000/repo-HEAD.tgz')
24+
t.equal(f.shortcut(), 'localhost:repo/x')
25+
26+
const g = gh.fromUrl('localhost:repo/x')
27+
t.ok(g, 'got a localhost repo from shortcut')
28+
t.equal(g.git(), f.git(), 'resolves to the same repo')
29+
t.equal(g.tarball(), f.tarball(), 'resolves to same tarball')

0 commit comments

Comments
 (0)
Please sign in to comment.