Skip to content

Commit

Permalink
request.post_vars() no longer discards empty values
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Jun 3, 2020
1 parent 9690ce6 commit 0934844
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion datasette/utils/asgi.py
Expand Up @@ -80,7 +80,7 @@ async def post_vars(self):
body += message.get("body", b"")
more_body = message.get("more_body", False)

return dict(parse_qsl(body.decode("utf-8")))
return dict(parse_qsl(body.decode("utf-8"), keep_blank_values=True))

@classmethod
def fake(cls, path_with_query_string, method="GET", scheme="http"):
Expand Down
8 changes: 6 additions & 2 deletions tests/test_internals_request.py
Expand Up @@ -16,10 +16,14 @@ async def test_request_post_vars():
}

async def receive():
return {"type": "http.request", "body": b"foo=bar&baz=1", "more_body": False}
return {
"type": "http.request",
"body": b"foo=bar&baz=1&empty=",
"more_body": False,
}

request = Request(scope, receive)
assert {"foo": "bar", "baz": "1"} == await request.post_vars()
assert {"foo": "bar", "baz": "1", "empty": ""} == await request.post_vars()


def test_request_args():
Expand Down

0 comments on commit 0934844

Please sign in to comment.