Repository navigation
Misleading 'Invalid port' error for IPv6 URL with unclosed bracket #3824
Replies: 1 comment
|
The port message comes from how The same split has a second effect. If the text after Checking the parsed host right after the authority match catches both cases before the port is looked at. Taking the part after --- a/httpx/_urlparse.py
+++ b/httpx/_urlparse.py
@@ -305,3 +305,10 @@ def urlparse(url: str = "", **kwargs: str | None) -> ParseResult:
authority_match = AUTHORITY_REGEX.match(authority)
assert authority_match is not None
authority_dict = authority_match.groupdict()
+
+ # An opening "[" with no closing "]" would otherwise be split at the
+ # first ":" and reported as an invalid port.
+ if authority_dict["host"].startswith("[") and not authority_dict["host"].endswith("]"):
+ hostport = authority.rpartition("@")[2]
+ raise InvalidURL(f"Invalid IPv6 address, missing closing ']': {hostport!r}")With that change on
|
Uh oh!
There was an error while loading. Please reload this page.
Summary
An IPv6 URL with an unclosed bracket produces a misleading error message.
Repro
Expected
A message about the malformed/unclosed IPv6 bracket (e.g. "Invalid IPv6 address: missing closing ']'"). The current message points the user at the port, which is not the actual problem.
Minor, error-message quality only. Checked on current master; no existing issue found.
All reactions