diff --git a/src/bitbucket/bbUtils.ts b/src/bitbucket/bbUtils.ts index 97df3cc6..3bf08d2a 100644 --- a/src/bitbucket/bbUtils.ts +++ b/src/bitbucket/bbUtils.ts @@ -149,3 +149,7 @@ export function workspaceRepoFor(repository: Repository): WorkspaceRepo { siteRemotes: siteRemotes, }; } + +export function encodePathParts(path: string) { + return path.split('/').map(encodeURIComponent).join('/'); +} diff --git a/src/bitbucket/bitbucket-cloud/pullRequests.ts b/src/bitbucket/bitbucket-cloud/pullRequests.ts index c3f1318c..3ebd3e98 100644 --- a/src/bitbucket/bitbucket-cloud/pullRequests.ts +++ b/src/bitbucket/bitbucket-cloud/pullRequests.ts @@ -27,6 +27,7 @@ import { WorkspaceRepo, } from '../model'; import { CloudRepositoriesApi } from './repositories'; +import { encodePathParts } from '../bbUtils'; export const maxItemsSupported = { commits: 100, @@ -794,7 +795,8 @@ export class CloudPullRequestApi implements PullRequestApi { return cachedValue; } - const { data } = await this.client.getRaw(`/repositories/${ownerSlug}/${repoSlug}/src/${commitHash}/${path}`); + const url = `/repositories/${ownerSlug}/${repoSlug}/src/${commitHash}/${encodePathParts(path)}`; + const { data } = await this.client.getRaw(url); this.fileContentCache.setItem(cacheKey, data, 5 * Time.MINUTES); diff --git a/src/bitbucket/bitbucket-server/pullRequests.ts b/src/bitbucket/bitbucket-server/pullRequests.ts index 344b812c..abec3efd 100644 --- a/src/bitbucket/bitbucket-server/pullRequests.ts +++ b/src/bitbucket/bitbucket-server/pullRequests.ts @@ -5,7 +5,7 @@ import { Container } from '../../container'; import { CacheMap } from '../../util/cachemap'; import { Time } from '../../util/time'; import { getFileNameFromPaths } from '../../views/pullrequest/diffViewHelper'; -import { clientForSite } from '../bbUtils'; +import { clientForSite, encodePathParts } from '../bbUtils'; import { HTTPClient } from '../httpClient'; import { ApprovalStatus, @@ -909,7 +909,8 @@ export class ServerPullRequestApi implements PullRequestApi { return cachedValue; } - const { data } = await this.client.getRaw(`/rest/api/1.0/projects/${ownerSlug}/repos/${repoSlug}/raw/${path}`, { + const url = `/rest/api/1.0/projects/${ownerSlug}/repos/${repoSlug}/raw/${encodePathParts(path)}`; + const { data } = await this.client.getRaw(url, { at: commitHash, });