Skip to content

Commit

Permalink
update_query({}) should be a no-op.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjpieters committed Apr 19, 2023
1 parent cc509d1 commit 86197ce
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGES/845.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed an issue with ``update_query()`` getting rid of the query when the argument
is empty but not ``None``.
10 changes: 6 additions & 4 deletions yarl/_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ def _get_str_query(self, *args, **kwargs):
raise ValueError("Either kwargs or single query parameter must be present")

if query is None:
query = ""
query = None
elif isinstance(query, Mapping):
quoter = self._QUERY_PART_QUOTER
query = "&".join(self._query_seq_pairs(quoter, query.items()))
Expand Down Expand Up @@ -998,7 +998,7 @@ def with_query(self, *args, **kwargs):
"""
# N.B. doesn't cleanup query/fragment

new_query = self._get_str_query(*args, **kwargs)
new_query = self._get_str_query(*args, **kwargs) or ""
return URL(
self._val._replace(path=self._val.path, query=new_query), encoded=True
)
Expand All @@ -1007,12 +1007,14 @@ def update_query(self, *args, **kwargs):
"""Return a new URL with query part updated."""
s = self._get_str_query(*args, **kwargs)
query = None
if s:
if s is not None:
new_query = MultiDict(parse_qsl(s, keep_blank_values=True))
query = MultiDict(self.query)
query.update(new_query)

return URL(self._val._replace(query=self._get_str_query(query)), encoded=True)
return URL(
self._val._replace(query=self._get_str_query(query) or ""), encoded=True
)

def with_fragment(self, fragment):
"""Return a new URL with fragment replaced.
Expand Down

0 comments on commit 86197ce

Please sign in to comment.