aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg/tasks
diff options
context:
space:
mode:
authorDennis Fink2026-11-12 22:44:25 +0100
committerDennis Fink2026-11-12 22:44:25 +0100
commit1db6b47f88dde5538efa433328987c70eab74d70 (patch)
tree1231cc03e603f8b22f5c35a51475d3acc4694621 /webmentions_ssg/tasks
parentc7993952c585b66acad5275e39dbf91cf662b975 (diff)
downloadwebmentions-ssg-1db6b47f88dde5538efa433328987c70eab74d70.tar.gz
webmentions-ssg-1db6b47f88dde5538efa433328987c70eab74d70.zip
fix(core): validate Redis Huey URL schemes
Parse Redis backend flavours explicitly so supported combinations preserve the correct redis or rediss scheme while malformed or unknown variants fail fast.
Diffstat (limited to 'webmentions_ssg/tasks')
-rw-r--r--webmentions_ssg/tasks/extension.py37
1 files changed, 18 insertions, 19 deletions
diff --git a/webmentions_ssg/tasks/extension.py b/webmentions_ssg/tasks/extension.py
index f7072b2..ee9c442 100644
--- a/webmentions_ssg/tasks/extension.py
+++ b/webmentions_ssg/tasks/extension.py
@@ -144,27 +144,26 @@ class Huey:
parsed = urlsplit(url)
scheme = parsed.scheme.lower()
- if scheme.startswith(("redis", "rediss")):
- fixed_url = urlunsplit(parsed._replace(scheme=scheme.split("+", 1)[0]))
-
- if scheme.endswith("priority+expire"):
- from huey import PriorityRedisExpireHuey
-
- return PriorityRedisExpireHuey, {"url": fixed_url}
-
- if scheme.endswith("priority"):
- from huey import PriorityRedisHuey
-
- return PriorityRedisHuey, {"url": fixed_url}
-
- if scheme.endswith("expire"):
- from huey import RedisExpireHuey
-
- return RedisExpireHuey, {"url": fixed_url}
+ base_scheme, separator, flavour = scheme.partition("+")
+ if base_scheme in {"redis", "rediss"}:
+ from huey import (
+ PriorityRedisExpireHuey,
+ PriorityRedisHuey,
+ RedisExpireHuey,
+ RedisHuey,
+ )
- from huey import RedisHuey
+ backends = {
+ "": RedisHuey,
+ "priority": PriorityRedisHuey,
+ "expire": RedisExpireHuey,
+ "priority+expire": PriorityRedisExpireHuey,
+ }
+ if flavour not in backends or (separator and not flavour):
+ raise RuntimeError(f"Unsupported HUEY_URL scheme: {scheme!r}")
- return RedisHuey, {"url": url}
+ fixed_url = urlunsplit(parsed._replace(scheme=base_scheme))
+ return backends[flavour], {"url": fixed_url}
if scheme == "sqlite":
from huey import SqliteHuey