diff --git a/src/bitbucket/bbUtils.ts b/src/bitbucket/bbUtils.ts index 4562cd860..14f64fca2 100644 --- a/src/bitbucket/bbUtils.ts +++ b/src/bitbucket/bbUtils.ts @@ -150,3 +150,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 f7f83944c..134967ca1 100644 --- a/src/bitbucket/bitbucket-cloud/pullRequests.ts +++ b/src/bitbucket/bitbucket-cloud/pullRequests.ts @@ -28,6 +28,7 @@ import { WorkspaceRepo, } from '../model'; import { CloudRepositoriesApi } from './repositories'; +import { encodePathParts } from '../bbUtils'; export const maxItemsSupported = { commits: 100, @@ -829,7 +830,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 17de966a4..80b4eec78 100644 --- a/src/bitbucket/bitbucket-server/pullRequests.ts +++ b/src/bitbucket/bitbucket-server/pullRequests.ts @@ -6,7 +6,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, @@ -944,7 +944,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, });