Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion playwright/_impl/_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ async def _inner_fetch(
form_data: Optional[List[NameValue]] = None
multipart_data: Optional[List[FormField]] = None
post_data_buffer: Optional[bytes] = None
if data:
if data is not None:
if isinstance(data, str):
if is_json_content_type(serialized_headers):
json_data = data if is_json_parsable(data) else json.dumps(data)
Expand Down
14 changes: 10 additions & 4 deletions tests/async/test_fetch_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,12 +448,18 @@ async def test_should_throw_an_error_when_max_redirects_is_less_than_0(
assert "'max_redirects' must be greater than or equal to '0'" in str(exc_info)


async def test_should_serialize_null_values_in_json(
async def test_should_serialize_request_data(
playwright: Playwright, server: Server
) -> None:
request = await playwright.request.new_context()
server.set_route("/echo", lambda req: (req.write(req.post_body), req.finish()))
response = await request.post(server.PREFIX + "/echo", data={"foo": None})
assert response.status == 200
assert await response.text() == '{"foo": null}'
for data, expected in [
({"foo": None}, '{"foo": null}'),
([], "[]"),
({}, "{}"),
("", ""),
]:
response = await request.post(server.PREFIX + "/echo", data=data)
assert response.status == 200
assert await response.text() == expected
await request.dispose()