params argument on URL should merge, not replace. (#653)

This commit is contained in:
Tom Christie 2019-12-20 10:46:35 +00:00 committed by GitHub
parent 5ee512d803
commit 74e5115b86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View 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.

View 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():