From 3a9fbdbcd6b819fb32e5bbe6c40227f2840d6e44 Mon Sep 17 00:00:00 2001 From: Aramis Sennyey Date: Sat, 2 Dec 2023 11:43:40 -0500 Subject: [PATCH] fix: update the catalog client to prevent double encoding of filter query params Signed-off-by: Aramis Sennyey --- packages/catalog-client/src/CatalogClient.test.ts | 6 +++--- packages/catalog-client/src/CatalogClient.ts | 6 ++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/catalog-client/src/CatalogClient.test.ts b/packages/catalog-client/src/CatalogClient.test.ts index 4892017032..745823471a 100644 --- a/packages/catalog-client/src/CatalogClient.test.ts +++ b/packages/catalog-client/src/CatalogClient.test.ts @@ -87,7 +87,7 @@ describe('CatalogClient', () => { server.use( rest.get(`${mockBaseUrl}/entities`, (req, res, ctx) => { expect(decodeURIComponent(req.url.search)).toBe( - '?filter=a=1,b=2,b=3,%C3%B6=%3D&filter=a=2&filter=c', + '?filter=a=1,b=2,b=3,ö==&filter=a=2&filter=c', ); return res(ctx.json([])); }), @@ -121,7 +121,7 @@ describe('CatalogClient', () => { server.use( rest.get(`${mockBaseUrl}/entities`, (req, res, ctx) => { expect(decodeURIComponent(req.url.search)).toBe( - '?filter=a=1,b=2,b=3,%C3%B6=%3D,c', + '?filter=a=1,b=2,b=3,ö==,c', ); return res(ctx.json([])); }), @@ -330,7 +330,7 @@ describe('CatalogClient', () => { expect(mockedEndpoint).toHaveBeenCalledTimes(1); expect( decodeURIComponent(mockedEndpoint.mock.calls[0][0].url.search), - ).toBe('?filter=a=1,b=2,b=3,%C3%B6=%3D&filter=a=2&filter=c'); + ).toBe('?filter=a=1,b=2,b=3,ö==&filter=a=2&filter=c'); }); it('should send query params correctly on initial request', async () => { diff --git a/packages/catalog-client/src/CatalogClient.ts b/packages/catalog-client/src/CatalogClient.ts index 511bf45c51..50219a0aa6 100644 --- a/packages/catalog-client/src/CatalogClient.ts +++ b/packages/catalog-client/src/CatalogClient.ts @@ -452,11 +452,9 @@ export class CatalogClient implements CatalogApi { for (const [key, value] of Object.entries(filterItem)) { for (const v of [value].flat()) { if (v === CATALOG_FILTER_EXISTS) { - filterParts.push(encodeURIComponent(key)); + filterParts.push(key); } else if (typeof v === 'string') { - filterParts.push( - `${encodeURIComponent(key)}=${encodeURIComponent(v)}`, - ); + filterParts.push(`${key}=${v}`); } } }