Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update_query({}) should be a no-op. #845

Merged
merged 1 commit into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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