Skip to content

Commit 1d0ac55

Browse files
authored
Merge pull request #153 from valkey-io/aiven-sal/url
Allow relative path in unix socket URLs
2 parents 02c2bfe + e9e3bfb commit 1d0ac55

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

tests/test_connection.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,10 @@ def test_unix_socket_connection_failure():
341341
str(e.value)
342342
== "Error 2 connecting to unix:///tmp/a.sock. No such file or directory."
343343
)
344+
345+
346+
def test_parsing_unix_socket_relative_path():
347+
parsed = parse_url("unix:./valkey.sock", False)
348+
assert parsed["path"] == "./valkey.sock"
349+
assert parsed["connection_class"] is UnixDomainSocketConnection
350+
assert len(parsed) == 2

valkey/_parsers/url_parser.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ def parse_url(url: str, async_connection: bool):
4040
supported_schemes = ["valkey", "valkeys", "redis", "rediss", "unix"]
4141
parsed: ParseResult = urlparse(url)
4242
kwargs: ConnectKwargs = {}
43+
lower_url = url.lower()
4344
pattern = re.compile(
44-
r"^(?:" + "|".join(map(re.escape, supported_schemes)) + r")://", re.IGNORECASE
45+
r"^(?:" + "|".join(map(re.escape, supported_schemes)) + r")://"
4546
)
46-
if not pattern.match(url):
47+
if not pattern.match(lower_url) and not lower_url.startswith("unix:"):
4748
raise ValueError(
4849
f"Valkey URL must specify one of the following schemes {supported_schemes}"
4950
)

0 commit comments

Comments
 (0)