File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ Started raising a :exc: `ValueError ` exception raised for corrupted
2+ IPv6 URL values.
3+
4+ These fixes the issue where exception :exc: `IndexError ` was
5+ leaking from the internal code because of not being handled and
6+ transformed into a user-facing error. The problem was happening
7+ under the following conditions: empty IPv6 URL, brackets in
8+ reverse order.
9+
10+ -- by :user: `MaelPic `.
Original file line number Diff line number Diff line change @@ -338,9 +338,26 @@ def test_ipv6_missing_right_bracket() -> None:
338338 URL ("http://[1dec:0:0:0::1/" )
339339
340340
341- def test_ipv4_brackets_not_allowed () -> None :
342- with pytest .raises (ValueError , match = "An IPv4 address cannot be in brackets" ):
343- URL ("http://[127.0.0.1]/" )
341+ @pytest .mark .parametrize (
342+ "url" ,
343+ (
344+ "http://[]/" ,
345+ "http://[1]/" ,
346+ "http://[127.0.0.1]/" ,
347+ "http://]1dec:0:0:0::1[/" ,
348+ ),
349+ ids = (
350+ "empty-IPv6-like-URL" ,
351+ "no-colons-in-IPv6" ,
352+ "IPv4-inside-brackets" ,
353+ "brackets-in-reversed-order" ,
354+ ),
355+ )
356+ def test_ipv6_invalid_url (url : str ) -> None :
357+ with pytest .raises (
358+ ValueError , match = "The IPv6 content between brackets is not valid"
359+ ):
360+ URL (url )
344361
345362
346363def test_ipfuture_brackets_not_allowed () -> None :
Original file line number Diff line number Diff line change @@ -69,11 +69,11 @@ def split_url(url: str) -> SplitURLType:
6969 # Valid bracketed hosts are defined in
7070 # https://www.rfc-editor.org/rfc/rfc3986#page-49
7171 # https://url.spec.whatwg.org/
72- if bracketed_host [0 ] == "v" :
72+ if bracketed_host and bracketed_host [0 ] == "v" :
7373 if not re .match (r"\Av[a-fA-F0-9]+\..+\Z" , bracketed_host ):
7474 raise ValueError ("IPvFuture address is invalid" )
7575 elif ":" not in bracketed_host :
76- raise ValueError ("An IPv4 address cannot be in brackets " )
76+ raise ValueError ("The IPv6 content between brackets is not valid " )
7777 if has_hash :
7878 url , _ , fragment = url .partition ("#" )
7979 if has_question_mark :
You can’t perform that action at this time.
0 commit comments