Skip to content

Commit 56e17b7

Browse files
committed
Merge branch 'master' of github.com:aio-libs/yarl
2 parents f544a79 + 0cbf83d commit 56e17b7

File tree

5 files changed

+24
-29
lines changed

5 files changed

+24
-29
lines changed

CHANGES.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CHANGES
22
=======
33

4-
0.19.0 (xxxx-xx-xx)
4+
1.0.0 (xxxx-xx-xx)
55
-------------------
66

77
* Use fast path if quoted string does not need requoting (#154)
@@ -17,6 +17,8 @@ CHANGES
1717

1818
* Support `encoded=True` in `yarl.URL.build()` (#158)
1919

20+
* Fix updating query with multiple keys (#160)
21+
2022
0.18.0 (2018-01-10)
2123
-------------------
2224

docs/api.rst

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -566,22 +566,14 @@ section generates a new *URL* instance.
566566
URL('http://example.com/path?a=b&b=2')
567567
>>> URL('http://example.com/path?a=b&b=1').update_query([('b', '2')])
568568
URL('http://example.com/path?a=b&b=2')
569+
>>> URL('http://example.com/path?a=b&c=e&c=f').update_query(c='d')
570+
URL('http://example.com/path?a=b&c=d')
571+
>>> URL('http://example.com/path?a=b').update_query('c=d&c=f')
572+
URL('http://example.com/path?a=b&c=d&c=f')
569573

570-
.. note::
571-
572-
Query string will be updated in a similar way to ``dict.update``. Multiple values will be dropped:
573-
574-
.. doctest::
575-
576-
>>> URL('http://example.com/path?a=b&c=e&c=f').update_query(c='d')
577-
URL('http://example.com/path?a=b&c=d')
578-
579-
When passing multiple values as an argument, only last value will be applied.
580-
581-
.. doctest::
574+
.. versionchanged:: 1.0
582575

583-
>>> URL('http://example.com/path?a=b').update_query('c=d&c=f')
584-
URL('http://example.com/path?a=b&c=f')
576+
All multiple key/value pairs are applied to the multi-dictionary.
585577

586578
.. method:: URL.with_fragment(port)
587579

requirements/wheel.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
cython==0.27.3
22
pytest==3.3.2
3+
multidict==4.0.0

tests/test_update_query.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def test_update_query():
2323

2424
assert url.update_query({'baz': 'foo'}) == expected_url
2525
assert url.update_query(baz='foo') == expected_url
26-
assert url.update_query("?baz=foo") == expected_url
26+
assert url.update_query("baz=foo") == expected_url
2727

2828

2929
def test_update_query_with_args_and_kwargs():
@@ -167,3 +167,10 @@ def test_with_query_only():
167167
url = URL()
168168
url2 = url.with_query(key='value')
169169
assert str(url2) == '?key=value'
170+
171+
172+
def test_update_query_multiple_keys():
173+
url = URL('http://example.com/path?a=1&a=2')
174+
u2 = url.update_query([('a', '3'), ('a', '4')])
175+
176+
assert str(u2) == 'http://example.com/path?a=3&a=4'

yarl/__init__.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import warnings
2-
from collections import OrderedDict
32
from collections.abc import Mapping, Sequence
43
from ipaddress import ip_address
54
from urllib.parse import (SplitResult, parse_qsl,
@@ -853,19 +852,13 @@ def with_query(self, *args, **kwargs):
853852

854853
def update_query(self, *args, **kwargs):
855854
"""Return a new URL with query part updated."""
856-
new_query = OrderedDict(
857-
map(
858-
lambda x: x.split('=', 1),
859-
self._QUERY_QUOTER(
860-
self._get_str_query(*args, **kwargs)
861-
).lstrip("?").split("&")
862-
)
863-
)
864-
query = OrderedDict(self.query)
855+
s = self._get_str_query(*args, **kwargs)
856+
new_query = MultiDict(parse_qsl(s, keep_blank_values=True))
857+
query = MultiDict(self.query)
865858
query.update(new_query)
866-
query = self._get_str_query(query)
867-
return URL(
868-
self._val._replace(path=self._val.path, query=query), encoded=True)
859+
860+
return URL(self._val._replace(query=self._get_str_query(query)),
861+
encoded=True)
869862

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

0 commit comments

Comments
 (0)