Fix empty query params (#2354)

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
This commit is contained in:
Tom Christie 2022-09-02 14:24:45 +01:00 committed by GitHub
parent 3eee17e69e
commit d5900cd40e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -540,7 +540,7 @@ class QueryParams(typing.Mapping[str, str]):
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:

View File

@ -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):