From eb5bd5a00658b43042f5227482bcfc7083f10274 Mon Sep 17 00:00:00 2001 From: nlf Date: Thu, 15 Oct 2020 14:53:58 -0700 Subject: [PATCH] fix: correctly filter out urls for tarballs in gitlab PR-URL: https://github.com/npm/hosted-git-info/pull/69 Credit: @nlf Close: #69 Reviewed-by: @isaacs --- git-host-info.js | 2 +- test/fixtures/gitlab.js | 10 ++++++++++ test/gitlab.js | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/git-host-info.js b/git-host-info.js index ffd401d..da3348f 100644 --- a/git-host-info.js +++ b/git-host-info.js @@ -25,7 +25,7 @@ var gitHosts = module.exports = { '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}', - 'pathmatch': /^[/]([^/]+)[/]((?!.*(\/-\/|\/repository\/archive\.tar\.gz\?=.*|\/repository\/[^/]+\/archive.tar.gz$)).*?)(?:[.]git|[/])?$/ + 'pathmatch': /^\/([^/]+)\/((?!.*(\/-\/|\/repository(\/[^/]+)?\/archive\.tar\.gz)).*?)(?:\.git|\/)?$/ }, gist: { 'protocols': [ 'git', 'git+ssh', 'git+https', 'ssh', 'https' ], diff --git a/test/fixtures/gitlab.js b/test/fixtures/gitlab.js index 33053da..928510c 100644 --- a/test/fixtures/gitlab.js +++ b/test/fixtures/gitlab.js @@ -24,6 +24,16 @@ module.exports = [ label: 'https.tar', isUndefined: true }, + { + host: function (p) { return 'https://' + p.domain + '/' + p.owner + '/' + p.project + '/repository/archive.tar.gz?ref=' + p.branch }, + label: 'https.tar', + isUndefined: true + }, + { + host: function (p) { return 'https://' + p.domain + '/' + p.owner + '/' + p.project + '/repository/archive.tar.gz' }, + label: 'https.tar', + isUndefined: true + }, { host: function (p) { return 'git+https://' + p.domain + '/' + p.owner + '/' + p.project }, label: 'git+https' diff --git a/test/gitlab.js b/test/gitlab.js index cd0f7d8..94d9a39 100644 --- a/test/gitlab.js +++ b/test/gitlab.js @@ -17,7 +17,7 @@ var testFixtures = function (t, params, fixtures) { tt.is(hostinfo, undefined) tt.end() }) - break + continue } t.test('hostinfo.https', function (tt) {