]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Fix empty query params (#2354)
authorTom Christie <tom@tomchristie.com>
Fri, 2 Sep 2022 13:24:45 +0000 (14:24 +0100)
committerGitHub <noreply@github.com>
Fri, 2 Sep 2022 13:24:45 +0000 (14:24 +0100)
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
httpx/_urls.py
tests/models/test_queryparams.py

index cf4df384c13d84b23499566e139d812bca6482fc..1211bbba9a33d202e2a7268256cf6c759a6b40e8 100644 (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:
index ba200f146d8cd8bda5d8b60786ad785a18468759..29b2ca634d73036db3b10e55e965a915e70de6e6 100644 (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):