Skip to content

Commit

Permalink
fix(gitlab): Do not URL encode slashes in project name for GitLab htt…
Browse files Browse the repository at this point in the history
…ps URL

PR-URL: #47
Credit: @mterrel
Close: #47
Reviewed-by: @isaacs
  • Loading branch information
mterrel authored and isaacs committed Aug 4, 2019
1 parent d5cf830 commit cbf04f9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions git-host-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var gitHosts = module.exports = {
'domain': 'gitlab.com',
'treepath': 'tree',
'bugstemplate': 'https://{domain}/{user}/{project}/issues',
'httpstemplate': 'git+https://{auth@}{domain}/{user}/{projectPath}.git{#committish}',
'tarballtemplate': 'https://{domain}/{user}/{project}/repository/archive.tar.gz?ref={committish}'
},
gist: {
Expand Down
2 changes: 2 additions & 0 deletions git-host.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ GitHost.prototype._fill = function (template, opts) {
var rawcommittish = vars.committish
var rawFragment = vars.fragment
var rawPath = vars.path
var rawProject = vars.project
Object.keys(vars).forEach(function (key) {
vars[key] = encodeURIComponent(vars[key])
})
Expand All @@ -44,6 +45,7 @@ GitHost.prototype._fill = function (template, opts) {
vars.fragment = vars.fragment ? vars.fragment : ''
vars['#path'] = rawPath ? '#' + this.hashformat(rawPath) : ''
vars['/path'] = vars.path ? '/' + vars.path : ''
vars.projectPath = rawProject.split('/').map(encodeURIComponent).join('/')
if (opts.noCommittish) {
vars['#committish'] = ''
vars['/tree/committish'] = ''
Expand Down
6 changes: 6 additions & 0 deletions test/gitlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,11 @@ test('fromUrl(gitlab url)', function (t) {
require('./lib/standard-tests')(verify, 'gitlab.com', 'gitlab')
require('./lib/standard-tests')(verify, 'www.gitlab.com', 'gitlab')

t.is(
HostedGit.fromUrl('gitlab:group/sub group1/subgroup2/repo').https(),
'git+https://gitlab.com/group/sub%20group1/subgroup2/repo.git',
'subgroups are delimited with slashes and url encoded (shortcut -> https)'
)

t.end()
})

0 comments on commit cbf04f9

Please # to comment.