Repository navigation
Potential issue: default-port normalization depends on scheme case ("HTTP://example.org:80/" keeps its port) #3817
Unanswered
Sun-Wukhan
asked this question in
Potential Issue
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Raising this here per the contributing guide, as PR creation on this repo is limited to collaborators. Found with property-based testing (round-trip and normalization invariants over generated URLs).
Default-port normalization currently depends on the case of the scheme, because urlparse() passes the raw scheme to normalize_port() instead of the lowercased one:
The string form of the first URL is not even a fixpoint: str(u) re-parses to a different URL, and copy_with() silently drops the port. The URL class docstring presents an uppercase scheme ("HTTPS://...") as parsing into normalized components, and states that the scheme "is normalized to always be lowercased" — the port lookup is the one place that still uses the un-normalized form.
Schemes are case-insensitive and are normalized to lowercase everywhere else in the parser, so the port lookup should use the normalized scheme too.
I have the one-line fix plus a regression test ready on a fork branch: https://github.com/Sun-Wukhan/httpx/tree/fix/url-scheme-case-port (the full tests/models suite passes with it). Happy for a maintainer to open the PR from it, or to open one myself if the restriction is lifted for it.
All reactions