Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix empty query params #2354

Merged
merged 2 commits into from Sep 2, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion httpx/_urls.py
Expand Up @@ -540,7 +540,7 @@ def __init__(
items: typing.Sequence[typing.Tuple[str, PrimitiveData]]
if value is None or isinstance(value, (str, bytes)):
value = value.decode("ascii") if isinstance(value, bytes) else value
self._dict = parse_qs(value)
self._dict = parse_qs(value, keep_blank_values=True)
elif isinstance(value, QueryParams):
self._dict = {k: list(v) for k, v in value._dict.items()}
else:
Expand Down
11 changes: 11 additions & 0 deletions tests/models/test_queryparams.py
Expand Up @@ -76,6 +76,17 @@ def test_queryparam_types():
assert str(q) == "a=1&a=2"


def test_empty_query_params():
q = httpx.QueryParams({"a": ""})
assert str(q) == "a="

q = httpx.QueryParams("a=")
assert str(q) == "a="

q = httpx.QueryParams("a")
assert str(q) == "a="


def test_queryparam_update_is_hard_deprecated():
q = httpx.QueryParams("a=123")
with pytest.raises(RuntimeError):
Expand Down