Match a slug whole, and compare an allowed host name without case

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Opus 5.5 committed 2026-09-29 19:42:10 +02:00
1 parent 0ffd0726e9
commit f61caddced
3 files changed
+26 -8

No files matched your search

+9 -6
View File
@@ -54,24 +54,27 @@ def is_web_url(url: str) -> bool:
def only(host: str) -> Callable[[str], bool]:
"""The allow-list of a board that is fetched from one host name only,
which is every host so far."""
return lambda h: h == host
which is every host so far. A host name has no case, and a slug that
names one (`Acme` of acme.recruitee.com) may be written with capitals."""
want = host.lower()
return lambda h: h.lower() == want
#: Matched whole (`fullmatch`, so not even a trailing newline slips past `$`).
#: A slug that is one URL path segment: what the hosts that put the slug in
#: the path accept, and nothing that could add a path, a query or a fragment.
_SEGMENT = re.compile(r"^[A-Za-z0-9._~%-]+$")
_SEGMENT = re.compile(r"[A-Za-z0-9._~%-]+")
#: A slug that is one DNS label, for the hosts that put it in the host name.
_LABEL = re.compile(r"^[A-Za-z0-9-]+$")
_LABEL = re.compile(r"[A-Za-z0-9-]+")
def path_slug_ok(slug: str) -> bool:
return bool(_SEGMENT.match(slug)) and slug not in (".", "..")
return bool(_SEGMENT.fullmatch(slug)) and slug not in (".", "..")
def label_slug_ok(slug: str) -> bool:
return bool(_LABEL.match(slug))
return bool(_LABEL.fullmatch(slug))
def parse_dt(value: Any) -> datetime | None: