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:
parent
4be69f3c95
commit
12cf07919f
@ -58,9 +58,13 @@ def _parse_ipify(data: dict) -> Optional[str]:
|
|||||||
return ip or None
|
return ip or None
|
||||||
|
|
||||||
|
|
||||||
def _state_slug(state: str) -> str:
|
def _state_slug(state) -> str:
|
||||||
"""lowercase ascii-folded state slug with underscores (e.g. 'New York' -> 'new_york')"""
|
"""lowercase ascii-folded state slug with underscores (e.g. 'New York' -> 'new_york')
|
||||||
folded = unicodedata.normalize("NFKD", state).encode("ascii", "ignore").decode("ascii")
|
|
||||||
|
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(" ", "_")
|
return folded.lower().replace(" ", "_")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user