Skip to content
Open
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: 1 addition & 1 deletion redis/asyncio/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1749,7 +1749,7 @@ def parse_url(url: str) -> ConnectKwargs:

for name, value_list in parse_qs(parsed.query).items():
if value_list and len(value_list) > 0:
value = unquote(value_list[0])
value = value_list[0]
parser = URL_QUERY_ARGUMENT_PARSERS.get(name)
if parser:
try:
Expand Down
2 changes: 1 addition & 1 deletion redis/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2291,7 +2291,7 @@ def parse_url(url):

for name, value in parse_qs(url.query).items():
if value and len(value) > 0:
value = unquote(value[0])
value = value[0]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this contradicts the from_url docstrings, which state "The username, password, hostname, path and all querystring values are passed through urllib.parse.unquote". Same text lives in client.py:185, cluster.py:660, asyncio/client.py:172 and asyncio/cluster.py:344, so all four need the querystring part dropped or this becomes an undocumented behavior change for anyone who double-encoded on purpose.

parser = URL_QUERY_ARGUMENT_PARSERS.get(name)
if parser:
try:
Expand Down
6 changes: 6 additions & 0 deletions tests/test_asyncio/test_connection_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,12 @@ def test_client_name_in_querystring(self):
pool = redis.ConnectionPool.from_url("redis://location?client_name=test-client")
assert pool.connection_kwargs["client_name"] == "test-client"

def test_querystring_values_are_decoded_once(self):
pool = redis.ConnectionPool.from_url(
"redis://location?client_name=worker%2520name"
)
assert pool.connection_kwargs["client_name"] == "worker%20name"

def test_invalid_extra_typed_querystring_options(self):
with pytest.raises(ValueError):
redis.ConnectionPool.from_url(
Expand Down
6 changes: 6 additions & 0 deletions tests/test_connection_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,12 @@ def test_client_name_in_querystring(self):
pool = redis.ConnectionPool.from_url("redis://location?client_name=test-client")
assert pool.connection_kwargs["client_name"] == "test-client"

def test_querystring_values_are_decoded_once(self):
pool = redis.ConnectionPool.from_url(
"redis://location?client_name=worker%2520name"
)
assert pool.connection_kwargs["client_name"] == "worker%20name"

def test_invalid_extra_typed_querystring_options(self):
with pytest.raises(ValueError):
redis.ConnectionPool.from_url(
Expand Down