URL.replace(hostname=...) creates an invalid authority for unbracketed IPv6 #3543
Unanswered
Str0k
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.
On main
f03f65c, passing an unbracketed IPv6 address ashostnametoURL.replace()produces an authority that cannot be parsed correctly.Expected:
https://[::1]:8443/path?a=1#anchor, with hostname::1and port8443. This also affects round-tripping a hostname obtained from another URL.I checked the IPv6 and URL.replace issues, PRs and discussions. #1965 preserves an existing bracketed hostname when other components change; this case supplies a new hostname explicitly.
A small patch brackets a supplied colon-containing hostname unless it is already bracketed, matching the existing scope-construction approach:
patch and regression tests.
Validation on Windows / Python 3.11.15:
tests/test_datastructures.py tests/test_requests.py tests/test_routing.py: 249 passed.The cases cover port omission, port zero, a normal port, mapped/scoped IPv6, already-bracketed input and hostname round trips.
Would accepting unbracketed IPv6 hostnames here be the intended behavior? Opening this discussion before a PR as requested by the contribution guide.
Prepared with Codex assistance.
All reactions