From cbf04f9a410356b0072cae1f9c1f2de6a2fc97ed Mon Sep 17 00:00:00 2001 From: Mark Terrel Date: Sun, 28 Jul 2019 16:42:09 -0600 Subject: [PATCH] fix(gitlab): Do not URL encode slashes in project name for GitLab https URL PR-URL: https://github.com/npm/hosted-git-info/pull/47 Credit: @mterrel Close: #47 Reviewed-by: @isaacs --- git-host-info.js | 1 + git-host.js | 2 ++ test/gitlab.js | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/git-host-info.js b/git-host-info.js index 06ab486..698924d 100644 --- a/git-host-info.js +++ b/git-host-info.js @@ -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: { diff --git a/git-host.js b/git-host.js index 37529ba..dd9036e 100644 --- a/git-host.js +++ b/git-host.js @@ -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]) }) @@ -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'] = '' diff --git a/test/gitlab.js b/test/gitlab.js index 1f22e7a..289d934 100644 --- a/test/gitlab.js +++ b/test/gitlab.js @@ -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() })