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:
1 parent
0ffd0726e9
commit
f61caddced
3 files changed
+26
-8
No files matched your search
@@ -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:
|
||||
|
||||
@@ -39,7 +39,7 @@ PAGE_SIZE = 50
|
||||
#: (`127.0.0.1`, `[::1]`) or a single word never names a host the fetch could
|
||||
#: be pointed at; `ats._get` still refuses every host but this one, redirects
|
||||
#: included.
|
||||
_HOST = re.compile(r"^[a-z0-9-]+(\.[a-z0-9-]+)*$")
|
||||
_HOST = re.compile(r"[a-z0-9-]+(\.[a-z0-9-]+)*")
|
||||
|
||||
#: Teamtailor's own namespace in the feed, the `tt:` of `tt:locations`.
|
||||
_TT = "{https://teamtailor.com/locations}"
|
||||
@@ -60,7 +60,7 @@ def site(slug: str) -> str:
|
||||
|
||||
def slug_ok(slug: str) -> bool:
|
||||
host = site(slug)
|
||||
return bool(slug.strip()) and bool(_HOST.match(host)) \
|
||||
return bool(slug) and slug == slug.strip() and bool(_HOST.fullmatch(host)) \
|
||||
and not host.rsplit(".", 1)[-1].isdigit()
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user