From 6f7886424fec6150f856446a4f2e36439f1ac2c5 Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 5 Jul 2022 11:19:35 +0200 Subject: [PATCH 1/3] chore: avoid double encoding of filepath Signed-off-by: blam --- .../integration/src/bitbucketServer/core.test.ts | 14 ++++++++++++++ packages/integration/src/bitbucketServer/core.ts | 4 +++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/integration/src/bitbucketServer/core.test.ts b/packages/integration/src/bitbucketServer/core.test.ts index 1c8f5d259c..076a2c7a4f 100644 --- a/packages/integration/src/bitbucketServer/core.test.ts +++ b/packages/integration/src/bitbucketServer/core.test.ts @@ -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', diff --git a/packages/integration/src/bitbucketServer/core.ts b/packages/integration/src/bitbucketServer/core.ts index 80dbc0443f..0c57b0d3ed 100644 --- a/packages/integration/src/bitbucketServer/core.ts +++ b/packages/integration/src/bitbucketServer/core.ts @@ -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}`; } From 4df3390795e137f43a370b335351456ffa3d974e Mon Sep 17 00:00:00 2001 From: blam Date: Tue, 5 Jul 2022 11:20:34 +0200 Subject: [PATCH 2/3] chore: added changeset Signed-off-by: blam --- .changeset/tender-terms-flash.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/tender-terms-flash.md diff --git a/.changeset/tender-terms-flash.md b/.changeset/tender-terms-flash.md new file mode 100644 index 0000000000..b8e02b3356 --- /dev/null +++ b/.changeset/tender-terms-flash.md @@ -0,0 +1,5 @@ +--- +'@backstage/integration': patch +--- + +Avoid double encoding of the filepath in `getBitbucketServerDownloadUrl` From 2d47dc92e2c5226e91ae3ce197cbb9d01b0b613b Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Tue, 5 Jul 2022 11:48:50 +0200 Subject: [PATCH 3/3] Update tender-terms-flash.md Signed-off-by: Patrik Oldsberg --- .changeset/tender-terms-flash.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/tender-terms-flash.md b/.changeset/tender-terms-flash.md index b8e02b3356..ca5fdb3799 100644 --- a/.changeset/tender-terms-flash.md +++ b/.changeset/tender-terms-flash.md @@ -2,4 +2,4 @@ '@backstage/integration': patch --- -Avoid double encoding of the filepath in `getBitbucketServerDownloadUrl` +Avoid double encoding of the file path in `getBitbucketServerDownloadUrl`