fix: update the catalog client to prevent double encoding of filter query params

Signed-off-by: Aramis Sennyey <aramiss@spotify.com>
This commit is contained in:
Aramis Sennyey
2023-12-02 11:43:40 -05:00
parent 701fdd4cad
commit 3a9fbdbcd6
2 changed files with 5 additions and 7 deletions
@@ -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 () => {
+2 -4
View File
@@ -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}`);
}
}
}