Merge pull request #12430 from backstage/blam/avoid-double-encoding-in-path

Avoid double encoding in `bitbucketServer` integration
This commit is contained in:
Ben Lambert
2022-07-05 13:10:17 +02:00
committed by GitHub
3 changed files with 22 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/integration': patch
---
Avoid double encoding of the file path in `getBitbucketServerDownloadUrl`
@@ -108,6 +108,20 @@ describe('bitbucketServer core', () => {
);
});
it('does not double encode the filepath', async () => {
const config: BitbucketServerIntegrationConfig = {
host: 'bitbucket.mycompany.net',
apiBaseUrl: 'https://api.bitbucket.mycompany.net/rest/api/1.0',
};
const result = await getBitbucketServerDownloadUrl(
'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',
@@ -83,7 +83,9 @@ export async function getBitbucketServerDownloadUrl(
// 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))}`
: '';
return `${config.apiBaseUrl}/projects/${project}/repos/${repoName}/archive?format=tgz&at=${branch}&prefix=${project}-${repoName}${path}`;
}