fix: C1 coerce non-str state in _state_slug so geo parse can't TypeError

a malformed non-string 'state' reached unicodedata.normalize and raised TypeError out of
fetch_location, breaking the 'None on any parse failure' contract; str() it first.

Signed-off-by: disqualifier <dev@disqualifier.me>
This commit is contained in:
disqualifier 2026-06-29 21:34:40 -04:00
parent 4be69f3c95
commit 12cf07919f

View File

@ -58,9 +58,13 @@ def _parse_ipify(data: dict) -> Optional[str]:
return ip or None
def _state_slug(state: str) -> str:
"""lowercase ascii-folded state slug with underscores (e.g. 'New York' -> 'new_york')"""
folded = unicodedata.normalize("NFKD", state).encode("ascii", "ignore").decode("ascii")
def _state_slug(state) -> str:
"""lowercase ascii-folded state slug with underscores (e.g. 'New York' -> 'new_york')
coerces to str first so a malformed non-string `state` doesn't raise TypeError out
of unicodedata.normalize and break the 'None on any parse failure' contract.
"""
folded = unicodedata.normalize("NFKD", str(state)).encode("ascii", "ignore").decode("ascii")
return folded.lower().replace(" ", "_")