Skip to content

Commit 85c58cf

Browse files
miss-islingtoncsreddy98blurb-it[bot]orsenthil
authored
[3.14] gh-105708: 'V' could be case insensitive for IPvFuture hostnames (GH-105709) (#153139)
gh-105708: 'V' could be case insensitive for IPvFuture hostnames (GH-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> Co-authored-by: Senthil Kumaran <senthil@python.org>
1 parent 7a11c23 commit 85c58cf

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
@@ -1426,15 +1426,20 @@ def test_splitting_bracketed_hosts(self):
14261426
self.assertEqual(p1.username, 'user')
14271427
self.assertEqual(p1.path, '/path')
14281428
self.assertEqual(p1.port, 1234)
1429-
p2 = urllib.parse.urlsplit('scheme://user@[0439:23af:2309::fae7%test]/path?query')
1430-
self.assertEqual(p2.hostname, '0439:23af:2309::fae7%test')
1429+
p2 = urllib.parse.urlsplit('scheme://user@[V6a.ip]:1234/path?query')
1430+
self.assertEqual(p2.hostname, 'v6a.ip')
14311431
self.assertEqual(p2.username, 'user')
14321432
self.assertEqual(p2.path, '/path')
1433-
self.assertIs(p2.port, None)
1434-
p3 = urllib.parse.urlsplit('scheme://user@[0439:23af:2309::fae7:1234:192.0.2.146%test]/path?query')
1435-
self.assertEqual(p3.hostname, '0439:23af:2309::fae7:1234:192.0.2.146%test')
1433+
self.assertEqual(p2.port, 1234)
1434+
p3 = urllib.parse.urlsplit('scheme://user@[0439:23af:2309::fae7%test]/path?query')
1435+
self.assertEqual(p3.hostname, '0439:23af:2309::fae7%test')
14361436
self.assertEqual(p3.username, 'user')
14371437
self.assertEqual(p3.path, '/path')
1438+
self.assertIs(p3.port, None)
1439+
p4 = urllib.parse.urlsplit('scheme://user@[0439:23af:2309::fae7:1234:192.0.2.146%test]/path?query')
1440+
self.assertEqual(p4.hostname, '0439:23af:2309::fae7:1234:192.0.2.146%test')
1441+
self.assertEqual(p4.username, 'user')
1442+
self.assertEqual(p4.path, '/path')
14381443

14391444
def test_port_casting_failure_message(self):
14401445
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
@@ -461,8 +461,8 @@ def _check_bracketed_netloc(netloc):
461461
# Valid bracketed hosts are defined in
462462
# https://www.rfc-editor.org/rfc/rfc3986#page-49 and https://url.spec.whatwg.org/
463463
def _check_bracketed_host(hostname):
464-
if hostname.startswith('v'):
465-
if not re.match(r"\Av[a-fA-F0-9]+\..+\z", hostname):
464+
if hostname.startswith(('v', 'V')):
465+
if not re.match(r"\A[vV][a-fA-F0-9]+\..+\z", hostname):
466466
raise ValueError(f"IPvFuture address is invalid")
467467
else:
468468
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)