Skip to content

Commit 59b90bd

Browse files
committed
fix(fetch): serialise empty array in 'data' as JSON
1 parent c6cc4c9 commit 59b90bd

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

playwright/_impl/_fetch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ async def _inner_fetch(
338338
form_data: Optional[List[NameValue]] = None
339339
multipart_data: Optional[List[FormField]] = None
340340
post_data_buffer: Optional[bytes] = None
341-
if data:
341+
if data is not None:
342342
if isinstance(data, str):
343343
if is_json_content_type(serialized_headers):
344344
json_data = data if is_json_parsable(data) else json.dumps(data)

tests/async/test_fetch_global.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,3 +457,14 @@ async def test_should_serialize_null_values_in_json(
457457
assert response.status == 200
458458
assert await response.text() == '{"foo": null}'
459459
await request.dispose()
460+
461+
462+
async def test_should_serialize_empty_array_as_json(
463+
playwright: Playwright, server: Server
464+
) -> None:
465+
request = await playwright.request.new_context()
466+
server.set_route("/echo", lambda req: (req.write(req.post_body), req.finish()))
467+
response = await request.post(server.PREFIX + "/echo", data=[])
468+
assert response.status == 200
469+
assert await response.text() == "[]"
470+
await request.dispose()

0 commit comments

Comments
 (0)