summaryrefslogtreecommitdiff
path: root/redis/connection.py
diff options
context:
space:
mode:
authorKlaas van Schelven <klaas@vanschelven.com>2022-08-21 12:46:31 +0200
committerGitHub <noreply@github.com>2022-08-21 13:46:31 +0300
commitb5ebada842c715e9ee74ea638a7e6d11afcddae1 (patch)
treef0aea59523208dbc4dc38c30ba01869a351ada8f /redis/connection.py
parentfde03fbd45981c204908fe2a82999acf8e95bbc4 (diff)
downloadredis-py-b5ebada842c715e9ee74ea638a7e6d11afcddae1.tar.gz
Be more strict about url scheme parsing (#2343)
The error message implied that urls had to start with `scheme://`. However, if the double slash was left out, the url parsed just fine and the part that was ostensibly intended to be the hostname ended up as part of the path, whereas the default (localhost) would be used for the hostname. This commit makes the check as strict as the error message implies by including a check for the double slash. Co-authored-by: dvora-h <67596500+dvora-h@users.noreply.github.com>
Diffstat (limited to 'redis/connection.py')
-rwxr-xr-xredis/connection.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/redis/connection.py b/redis/connection.py
index 3438baf..96645ba 100755
--- a/redis/connection.py
+++ b/redis/connection.py
@@ -1166,6 +1166,16 @@ URL_QUERY_ARGUMENT_PARSERS = {
def parse_url(url):
+ if not (
+ url.startswith("redis://")
+ or url.startswith("rediss://")
+ or url.startswith("unix://")
+ ):
+ raise ValueError(
+ "Redis URL must specify one of the following "
+ "schemes (redis://, rediss://, unix://)"
+ )
+
url = urlparse(url)
kwargs = {}
@@ -1192,7 +1202,7 @@ def parse_url(url):
kwargs["path"] = unquote(url.path)
kwargs["connection_class"] = UnixDomainSocketConnection
- elif url.scheme in ("redis", "rediss"):
+ else: # implied: url.scheme in ("redis", "rediss"):
if url.hostname:
kwargs["host"] = unquote(url.hostname)
if url.port:
@@ -1208,11 +1218,6 @@ def parse_url(url):
if url.scheme == "rediss":
kwargs["connection_class"] = SSLConnection
- else:
- raise ValueError(
- "Redis URL must specify one of the following "
- "schemes (redis://, rediss://, unix://)"
- )
return kwargs