Skip to content

Commit

Permalink
Encode path parameter at GitLab getContentUrl (#1967)
Browse files Browse the repository at this point in the history
  • Loading branch information
jordeu committed Mar 12, 2021
1 parent 535c2bb commit 6f80f65
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ class GitlabRepositoryProvider extends RepositoryProvider {
// https://docs.gitlab.com/ee/api/repository_files.html#get-raw-file-from-repository
//
final ref = revision ?: getDefaultBranch()
return "${config.endpoint}/api/v4/projects/${getProjectName()}/repository/files/${path}?ref=${ref}"
final encodedPath = URLEncoder.encode(path,'utf-8')
return "${config.endpoint}/api/v4/projects/${getProjectName()}/repository/files/${encodedPath}?ref=${ref}"
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,9 @@ class GitlabRepositoryProviderTest extends Specification {
.setRevision('the-commit-id')
.getContentUrl('main.nf') == 'https://gitlab.com/api/v4/projects/pditommaso%2Fhello/repository/files/main.nf?ref=the-commit-id'

and:
new GitlabRepositoryProvider('pditommaso/hello', obj)
.getContentUrl('conf/extra.conf') == 'https://gitlab.com/api/v4/projects/pditommaso%2Fhello/repository/files/conf%2Fextra.conf?ref=master'

}
}

0 comments on commit 6f80f65

Please sign in to comment.