Skip to content

Commit

Permalink
Fixes 5434 -broken diffs for odd file names
Browse files Browse the repository at this point in the history
  • Loading branch information
marcellourbani committed Feb 13, 2025
1 parent 7ecc8da commit af333bc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/bitbucket/bbUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,7 @@ export function workspaceRepoFor(repository: Repository): WorkspaceRepo {
siteRemotes: siteRemotes,
};
}

export function encodePathParts(path: string) {
return path.split('/').map(encodeURIComponent).join('/');
}
4 changes: 3 additions & 1 deletion src/bitbucket/bitbucket-cloud/pullRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
WorkspaceRepo,
} from '../model';
import { CloudRepositoriesApi } from './repositories';
import { encodePathParts } from '../bbUtils';

export const maxItemsSupported = {
commits: 100,
Expand Down Expand Up @@ -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);

Expand Down
5 changes: 3 additions & 2 deletions src/bitbucket/bitbucket-server/pullRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
});

Expand Down

0 comments on commit af333bc

Please sign in to comment.