From 65b5c047bc7fdf99ff7e4e0d07dace41e28d7f57 Mon Sep 17 00:00:00 2001 From: Salvatore Mesoraca Date: Fri, 13 Dec 2024 17:02:49 +0100 Subject: [PATCH 1/2] Allow relative path in unix socket URLs Close #123 Signed-off-by: Salvatore Mesoraca --- valkey/_parsers/url_parser.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/valkey/_parsers/url_parser.py b/valkey/_parsers/url_parser.py index b85b18e6..5f26cdd0 100644 --- a/valkey/_parsers/url_parser.py +++ b/valkey/_parsers/url_parser.py @@ -40,10 +40,11 @@ def parse_url(url: str, async_connection: bool): supported_schemes = ["valkey", "valkeys", "redis", "rediss", "unix"] parsed: ParseResult = urlparse(url) kwargs: ConnectKwargs = {} + lower_url = url.lower() pattern = re.compile( - r"^(?:" + "|".join(map(re.escape, supported_schemes)) + r")://", re.IGNORECASE + r"^(?:" + "|".join(map(re.escape, supported_schemes)) + r")://" ) - if not pattern.match(url): + if not pattern.match(lower_url) and not lower_url.startswith("unix:"): raise ValueError( f"Valkey URL must specify one of the following schemes {supported_schemes}" ) From e9e3bfb16185fc4cde25c70721f3a22b31d54e13 Mon Sep 17 00:00:00 2001 From: Salvatore Mesoraca Date: Fri, 13 Dec 2024 18:03:51 +0100 Subject: [PATCH 2/2] Add tests for unix socket with relative path Signed-off-by: Salvatore Mesoraca --- tests/test_connection.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_connection.py b/tests/test_connection.py index 545a7d3f..5fac2502 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -341,3 +341,10 @@ def test_unix_socket_connection_failure(): str(e.value) == "Error 2 connecting to unix:///tmp/a.sock. No such file or directory." ) + + +def test_parsing_unix_socket_relative_path(): + parsed = parse_url("unix:./valkey.sock", False) + assert parsed["path"] == "./valkey.sock" + assert parsed["connection_class"] is UnixDomainSocketConnection + assert len(parsed) == 2