fix(github-http): return None on malformed GHES port instead of raising#3379
Open
jawwad-ali wants to merge 1 commit into
Open
fix(github-http): return None on malformed GHES port instead of raising#3379jawwad-ali wants to merge 1 commit into
jawwad-ali wants to merge 1 commit into
Conversation
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
resolve_github_release_asset_api_urlis contracted to either resolve a browser release-download URL to its REST API asset URL or returnNone— every unresolvable case (unknown host, not-an-asset path, network error, missing asset) returnsNone. But the GHES branch builds the authority viaparsed.port:urllib's.portraisesValueErroron a malformed port. So an allowlisted GHES host with a bad port (e.g.https://ghes.example:notaport/...) crashes the caller instead of returningNone. Reproduced on main @92b7cf7:ValueError: Port could not be cast to integer value as 'notaport'.Fix
Read
parsed.portinside atry/except ValueError: return None, matching the function's existing gracefulreturn Nonebehavior.Testing
New
test_returns_none_on_malformed_ghes_port: an allowlisted GHES host with:notaportreturnsNoneand induces no network call. Fails before (ValueError— verified by source-stash), passes after. The existing valid-port GHES test still passes (happy path unchanged). Fulltest_github_http.py: 27 passed.uvx ruff checkclean.AI Disclosure
Found and fixed with Claude Code (Claude Fable 5) under my direction. AI spotted the unguarded
parsed.portagainst the function's return-None contract; I reproduced the ValueError, verified fail-before/pass-after, and reviewed the diff.