Skip to content

Commit

Permalink
fix(2398): URI encode path to file for getFile (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkyi authored Apr 9, 2021
1 parent 99c1b6b commit 36d2e93
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 36d2e93

Please sign in to comment.