diff --git a/.changeset/slick-lamps-clap.md b/.changeset/slick-lamps-clap.md new file mode 100644 index 0000000000..af9e1521d3 --- /dev/null +++ b/.changeset/slick-lamps-clap.md @@ -0,0 +1,11 @@ +--- +'@backstage/plugin-catalog-backend-module-msgraph': minor +--- + +Encode query filters for requests made to msgraph. If you currently have manually encoded characters in a filter, this is a breaking change and must be updated to avoid requests being double encoded. + +```diff +user: +- filter: department in('MARKETING', 'RESEARCH %26 DEVELOPMENT') ++ filter: department in('MARKETING', 'RESEARCH & DEVELOPMENT') +``` diff --git a/plugins/catalog-backend-module-msgraph/src/microsoftGraph/client.test.ts b/plugins/catalog-backend-module-msgraph/src/microsoftGraph/client.test.ts index 1f59ee9c93..fa198e9a28 100644 --- a/plugins/catalog-backend-module-msgraph/src/microsoftGraph/client.test.ts +++ b/plugins/catalog-backend-module-msgraph/src/microsoftGraph/client.test.ts @@ -87,7 +87,25 @@ describe('MicrosoftGraphClient', () => { expect(response.status).toBe(200); expect(await response.json()).toEqual({ queryString: - '?$filter=test%20eq%20true&$select=id,children&$expand=children&$top=471', + '?%24filter=test%20eq%20true&%24select=id%2Cchildren&%24expand=children&%24top=471', + }); + }); + + it('should correctly encode filter with special characters like "&"', async () => { + worker.use( + rest.get('https://example.com/users', (req, res, ctx) => + res(ctx.status(200), ctx.json({ queryString: req.url.search })), + ), + ); + + const response = await client.requestApi('users', { + filter: "department eq 'research & development'", + }); + + expect(response.status).toBe(200); + expect(await response.json()).toEqual({ + queryString: + '?%24filter=department%20eq%20%27research%20%26%20development%27', }); }); diff --git a/plugins/catalog-backend-module-msgraph/src/microsoftGraph/client.ts b/plugins/catalog-backend-module-msgraph/src/microsoftGraph/client.ts index 81b57273a8..83d0f0647b 100644 --- a/plugins/catalog-backend-module-msgraph/src/microsoftGraph/client.ts +++ b/plugins/catalog-backend-module-msgraph/src/microsoftGraph/client.ts @@ -195,8 +195,7 @@ export class MicrosoftGraphClient { }, { addQueryPrefix: true, - // Microsoft Graph doesn't like an encoded query string - encode: false, + encode: true, }, );