]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
params argument on URL should merge, not replace. (#653)
authorTom Christie <tom@tomchristie.com>
Fri, 20 Dec 2019 10:46:35 +0000 (10:46 +0000)
committerGitHub <noreply@github.com>
Fri, 20 Dec 2019 10:46:35 +0000 (10:46 +0000)
httpx/models.py
tests/models/test_url.py

index ad3599b717433099ffdb50d36cc13a9eb061a6de..fc938c3ebf67e31bbd7803aff3c6d7273c8c0103 100644 (file)
@@ -90,9 +90,14 @@ class URL:
         if self.is_absolute_url:
             self._uri_reference = self._uri_reference.normalize()
 
-        # Add any query parameters.
+        # Add any query parameters, merging with any in the URL if needed.
         if params:
-            query_string = str(QueryParams(params))
+            if self._uri_reference.query:
+                url_params = QueryParams(self._uri_reference.query)
+                url_params.update(params)
+                query_string = str(url_params)
+            else:
+                query_string = str(QueryParams(params))
             self._uri_reference = self._uri_reference.copy_with(query=query_string)
 
         # Enforce absolute URLs by default.
index 1415ee9143a2113d7e64058c14c4a32162af17a4..491d0a4b46655b4d0b5bb1ecfc4d80108a4352fe 100644 (file)
@@ -89,7 +89,7 @@ def test_url_params():
     assert str(url) == "https://example.org:123/path/to/somewhere?a=123"
 
     url = URL("https://example.org:123/path/to/somewhere?b=456", params={"a": "123"})
-    assert str(url) == "https://example.org:123/path/to/somewhere?a=123"
+    assert str(url) == "https://example.org:123/path/to/somewhere?b=456&a=123"
 
 
 def test_url_join():