mirror of
https://github.com/github/spec-kit.git
synced 2026-07-11 02:24:16 +08:00
fix(github-http): return None on malformed GHES port instead of raising (#3379)
resolve_github_release_asset_api_url's is_ghes branch built the authority with 'parsed.port', which raises ValueError on a malformed port (e.g. host:notaport). The function's contract is to resolve or return None, never raise — every other unresolvable case returns None. An allowlisted GHES host with a bad port therefore crashed the caller. Read parsed.port defensively and return None on ValueError. Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -127,7 +127,14 @@ def resolve_github_release_asset_api_url(
|
||||
if hostname == "github.com":
|
||||
api_base = "https://api.github.com"
|
||||
elif is_ghes:
|
||||
authority = hostname if parsed.port is None else f"{hostname}:{parsed.port}"
|
||||
# ``parsed.port`` raises ValueError on a malformed port (e.g.
|
||||
# ``host:notaport``); the function's contract is to return None for
|
||||
# anything it can't resolve, not to raise.
|
||||
try:
|
||||
port = parsed.port
|
||||
except ValueError:
|
||||
return None
|
||||
authority = hostname if port is None else f"{hostname}:{port}"
|
||||
api_base = f"{parsed.scheme}://{authority}/api/v3"
|
||||
else:
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user