Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow relative path in unix socket URLs #153

Merged
merged 2 commits into from
Dec 16, 2024
Merged
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
7 changes: 7 additions & 0 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions valkey/_parsers/url_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
)
Expand Down
Loading