Skip to content

Commit 8d751cf

Browse files
authored
fix(fetch): filter out undefined params (#34654)
1 parent 365f411 commit 8d751cf

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

packages/playwright-core/src/client/fetch.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,10 @@ function objectToArray(map?: { [key: string]: any }): NameValue[] | undefined {
416416
if (!map)
417417
return undefined;
418418
const result = [];
419-
for (const [name, value] of Object.entries(map))
420-
result.push({ name, value: String(value) });
419+
for (const [name, value] of Object.entries(map)) {
420+
if (value !== undefined)
421+
result.push({ name, value: String(value) });
422+
}
421423
return result;
422424
}
423425

tests/library/browsercontext-fetch.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,7 @@ it('should send secure cookie over http for localhost', async ({ page, server })
11831183
expect(serverRequest.headers.cookie).toBe('a=v');
11841184
});
11851185

1186-
it('should accept bool and numeric params', async ({ page, server }) => {
1186+
it('should accept bool and numeric params and filter out undefined', async ({ page, server }) => {
11871187
let request;
11881188
const url = new URL(server.EMPTY_PAGE);
11891189
url.searchParams.set('str', 's');
@@ -1200,13 +1200,15 @@ it('should accept bool and numeric params', async ({ page, server }) => {
12001200
'num': 10,
12011201
'bool': true,
12021202
'bool2': false,
1203+
'none': undefined,
12031204
}
12041205
});
12051206
const params = new URLSearchParams(request!.url.substr(request!.url.indexOf('?')));
12061207
expect(params.get('str')).toEqual('s');
12071208
expect(params.get('num')).toEqual('10');
12081209
expect(params.get('bool')).toEqual('true');
12091210
expect(params.get('bool2')).toEqual('false');
1211+
expect(params.has('none')).toBe(false);
12101212
});
12111213

12121214
it('should abort requests when browser context closes', async ({ contextFactory, server }) => {

0 commit comments

Comments
 (0)