From 36d2e93ed331a4e0c0c347bdeb80ac4cf53784c3 Mon Sep 17 00:00:00 2001 From: Tiffany K Date: Fri, 9 Apr 2021 09:55:02 -0700 Subject: [PATCH] fix(2398): URI encode path to file for getFile (#39) --- index.js | 2 +- package.json | 2 +- test/index.test.js | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index fc15ee4..9c4523b 100644 --- a/index.js +++ b/index.js @@ -771,7 +771,7 @@ class GitlabScm extends Scm { bearer: token }, url: `${this.config.gitlabProtocol}://${this.config.gitlabHost}/api/v4` + - `/projects/${repoId}/repository/files/${fullPath}`, + `/projects/${repoId}/repository/files/${encodeURIComponent(fullPath)}`, qs: { ref: ref || branch } diff --git a/package.json b/package.json index cdb33fa..2258e25 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "circuit-fuses": "^4.0.5", "joi": "^17.2.0", "request": "^2.80.0", - "screwdriver-data-schema": "^21.0.0", + "screwdriver-data-schema": "^21.2.7", "screwdriver-scm-base": "^7.0.0" }, "release": { diff --git a/test/index.test.js b/test/index.test.js index 78e4071..fb1d881 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -874,7 +874,7 @@ describe('index', function () { describe('getFile', () => { const apiUrl = 'https://gitlab.com/api/v4/projects/repoId' + - '/repository/files/path/to/file.txt'; + '/repository/files/path%2Fto%2Ffile.txt'; let expectedOptions; let fakeResponse; let params; @@ -917,7 +917,7 @@ describe('index', function () { it('resolves to correct commit sha when rootDir is passed in', () => { params.scmUri = 'hostName:repoId:branchName:path/to/source'; expectedOptions.url = 'https://gitlab.com/api/v4/projects/repoId' + - '/repository/files/path/to/source/path/to/file.txt'; + '/repository/files/path%2Fto%2Fsource%2Fpath%2Fto%2Ffile.txt'; return scm.getFile(params).then((content) => { assert.calledWith(requestMock, expectedOptions);