Skip to content

Commit

Permalink
Avoid double encoding in bitbucket integration
Browse files Browse the repository at this point in the history
Signed-off-by: Namco <namco1992@gmail.com>
  • Loading branch information
namco1992 committed Jul 22, 2022
1 parent 795a804 commit c4b460a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/pretty-gifts-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@backstage/integration': patch
---

Avoid double encoding of the file path in `getBitbucketDownloadUrl`
14 changes: 14 additions & 0 deletions packages/integration/src/bitbucket/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,20 @@ describe('bitbucket core', () => {
);
});

it('does not double encode the filepath', async () => {
const config: BitbucketIntegrationConfig = {
host: 'bitbucket.mycompany.net',
apiBaseUrl: 'https://api.bitbucket.mycompany.net/rest/api/1.0',
};
const result = await getBitbucketDownloadUrl(
'https://bitbucket.mycompany.net/projects/backstage/repos/mock/browse/%2Fdocs?at=some-branch',
config,
);
expect(result).toEqual(
'https://api.bitbucket.mycompany.net/rest/api/1.0/projects/backstage/repos/mock/archive?format=tgz&at=some-branch&prefix=backstage-mock&path=%2Fdocs',
);
});

it('do not add path param if no path is specified for Bitbucket Server', async () => {
const defaultBranchResponse = {
displayId: 'main',
Expand Down
4 changes: 3 additions & 1 deletion packages/integration/src/bitbucket/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ export async function getBitbucketDownloadUrl(
// path will limit the downloaded content
// /docs will only download the docs folder and everything below it
// /docs/index.md will download the docs folder and everything below it
const path = filepath ? `&path=${encodeURIComponent(filepath)}` : '';
const path = filepath
? `&path=${encodeURIComponent(decodeURIComponent(filepath))}`
: '';
const archiveUrl = isHosted
? `${protocol}://${resource}/${project}/${repoName}/get/${branch}.tar.gz`
: `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/archive?format=tgz&at=${branch}&prefix=${project}-${repoName}${path}`;
Expand Down

0 comments on commit c4b460a

Please sign in to comment.