File tree Expand file tree Collapse file tree 3 files changed +32
-5
lines changed Expand file tree Collapse file tree 3 files changed +32
-5
lines changed 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:
338
338
URL ("http://[1dec:0:0:0::1/" )
339
339
340
340
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 )
344
361
345
362
346
363
def 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:
69
69
# Valid bracketed hosts are defined in
70
70
# https://www.rfc-editor.org/rfc/rfc3986#page-49
71
71
# https://url.spec.whatwg.org/
72
- if bracketed_host [0 ] == "v" :
72
+ if bracketed_host and bracketed_host [0 ] == "v" :
73
73
if not re .match (r"\Av[a-fA-F0-9]+\..+\Z" , bracketed_host ):
74
74
raise ValueError ("IPvFuture address is invalid" )
75
75
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 " )
77
77
if has_hash :
78
78
url , _ , fragment = url .partition ("#" )
79
79
if has_question_mark :
You can’t perform that action at this time.
0 commit comments