Skip to content

Commit 491d830

Browse files
orsenthilcsreddy98blurb-it[bot]
authored
[3.13] gh-105708: 'V' could be case insensitive for IPvFuture hostnames (#5709) (#153140)
gh-105708: 'V' could be case insensitive for IPvFuture hostnames (#105709) * gh-105708: 'V' could be case insensitive for IPvFuture hostnames * gh-105708: 'V' could be case insensitive for IPvFuture hostnames & checking empty hostnames * 📜🤖 Added by blurb_it. * Fix the Merge changing \z to \Z. * Fixed the News Entry. * Fix the lint. --------- (cherry picked from commit a47a66c) Co-authored-by: Chandra <csreddy1998@gmail.com> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
1 parent 4f479ac commit 491d830

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

Lib/test/test_urlparse.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,15 +1290,20 @@ def test_splitting_bracketed_hosts(self):
12901290
self.assertEqual(p1.username, 'user')
12911291
self.assertEqual(p1.path, '/path')
12921292
self.assertEqual(p1.port, 1234)
1293-
p2 = urllib.parse.urlsplit('scheme://user@[0439:23af:2309::fae7%test]/path?query')
1294-
self.assertEqual(p2.hostname, '0439:23af:2309::fae7%test')
1293+
p2 = urllib.parse.urlsplit('scheme://user@[V6a.ip]:1234/path?query')
1294+
self.assertEqual(p2.hostname, 'v6a.ip')
12951295
self.assertEqual(p2.username, 'user')
12961296
self.assertEqual(p2.path, '/path')
1297-
self.assertIs(p2.port, None)
1298-
p3 = urllib.parse.urlsplit('scheme://user@[0439:23af:2309::fae7:1234:192.0.2.146%test]/path?query')
1299-
self.assertEqual(p3.hostname, '0439:23af:2309::fae7:1234:192.0.2.146%test')
1297+
self.assertEqual(p2.port, 1234)
1298+
p3 = urllib.parse.urlsplit('scheme://user@[0439:23af:2309::fae7%test]/path?query')
1299+
self.assertEqual(p3.hostname, '0439:23af:2309::fae7%test')
13001300
self.assertEqual(p3.username, 'user')
13011301
self.assertEqual(p3.path, '/path')
1302+
self.assertIs(p3.port, None)
1303+
p4 = urllib.parse.urlsplit('scheme://user@[0439:23af:2309::fae7:1234:192.0.2.146%test]/path?query')
1304+
self.assertEqual(p4.hostname, '0439:23af:2309::fae7:1234:192.0.2.146%test')
1305+
self.assertEqual(p4.username, 'user')
1306+
self.assertEqual(p4.path, '/path')
13021307

13031308
def test_port_casting_failure_message(self):
13041309
message = "Port could not be cast to integer value as 'oracle'"

Lib/urllib/parse.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,8 @@ def _check_bracketed_netloc(netloc):
458458
# Valid bracketed hosts are defined in
459459
# https://www.rfc-editor.org/rfc/rfc3986#page-49 and https://url.spec.whatwg.org/
460460
def _check_bracketed_host(hostname):
461-
if hostname.startswith('v'):
462-
if not re.match(r"\Av[a-fA-F0-9]+\..+\Z", hostname):
461+
if hostname.startswith(('v', 'V')):
462+
if not re.match(r"\A[vV][a-fA-F0-9]+\..+\Z", hostname):
463463
raise ValueError(f"IPvFuture address is invalid")
464464
else:
465465
ip = ipaddress.ip_address(hostname) # Throws Value Error if not IPv6 or IPv4
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Accept an uppercase V prefix in IPvFuture addresses in :func:`urllib.parse.urlsplit`.

0 commit comments

Comments
 (0)