fix(fetch): filter out undefined `params` (#34654)

This commit is contained in:
Dmitry Gozman 2025-02-06 15:16:45 +00:00 committed by GitHub
parent 365f411548
commit 8d751cfe50
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 3 deletions

View File

@ -416,8 +416,10 @@ function objectToArray(map?: { [key: string]: any }): NameValue[] | undefined {
if (!map) if (!map)
return undefined; return undefined;
const result = []; const result = [];
for (const [name, value] of Object.entries(map)) for (const [name, value] of Object.entries(map)) {
result.push({ name, value: String(value) }); if (value !== undefined)
result.push({ name, value: String(value) });
}
return result; return result;
} }

View File

@ -1183,7 +1183,7 @@ it('should send secure cookie over http for localhost', async ({ page, server })
expect(serverRequest.headers.cookie).toBe('a=v'); expect(serverRequest.headers.cookie).toBe('a=v');
}); });
it('should accept bool and numeric params', async ({ page, server }) => { it('should accept bool and numeric params and filter out undefined', async ({ page, server }) => {
let request; let request;
const url = new URL(server.EMPTY_PAGE); const url = new URL(server.EMPTY_PAGE);
url.searchParams.set('str', 's'); url.searchParams.set('str', 's');
@ -1200,6 +1200,7 @@ it('should accept bool and numeric params', async ({ page, server }) => {
'num': 10, 'num': 10,
'bool': true, 'bool': true,
'bool2': false, 'bool2': false,
'none': undefined,
} }
}); });
const params = new URLSearchParams(request!.url.substr(request!.url.indexOf('?'))); const params = new URLSearchParams(request!.url.substr(request!.url.indexOf('?')));
@ -1207,6 +1208,7 @@ it('should accept bool and numeric params', async ({ page, server }) => {
expect(params.get('num')).toEqual('10'); expect(params.get('num')).toEqual('10');
expect(params.get('bool')).toEqual('true'); expect(params.get('bool')).toEqual('true');
expect(params.get('bool2')).toEqual('false'); expect(params.get('bool2')).toEqual('false');
expect(params.has('none')).toBe(false);
}); });
it('should abort requests when browser context closes', async ({ contextFactory, server }) => { it('should abort requests when browser context closes', async ({ contextFactory, server }) => {