Skip to content

Commit a47a66c

Browse files
csreddy98blurb-it[bot]orsenthil
authored
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. --------- Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Senthil Kumaran <senthil@python.org>
1 parent 89afed2 commit a47a66c

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
@@ -1653,15 +1653,20 @@ def test_splitting_bracketed_hosts(self):
16531653
self.assertEqual(p1.username, 'user')
16541654
self.assertEqual(p1.path, '/path')
16551655
self.assertEqual(p1.port, 1234)
1656-
p2 = urllib.parse.urlsplit('scheme://user@[0439:23af:2309::fae7%test]/path?query')
1657-
self.assertEqual(p2.hostname, '0439:23af:2309::fae7%test')
1656+
p2 = urllib.parse.urlsplit('scheme://user@[V6a.ip]:1234/path?query')
1657+
self.assertEqual(p2.hostname, 'v6a.ip')
16581658
self.assertEqual(p2.username, 'user')
16591659
self.assertEqual(p2.path, '/path')
1660-
self.assertIs(p2.port, None)
1661-
p3 = urllib.parse.urlsplit('scheme://user@[0439:23af:2309::fae7:1234:192.0.2.146%test]/path?query')
1662-
self.assertEqual(p3.hostname, '0439:23af:2309::fae7:1234:192.0.2.146%test')
1660+
self.assertEqual(p2.port, 1234)
1661+
p3 = urllib.parse.urlsplit('scheme://user@[0439:23af:2309::fae7%test]/path?query')
1662+
self.assertEqual(p3.hostname, '0439:23af:2309::fae7%test')
16631663
self.assertEqual(p3.username, 'user')
16641664
self.assertEqual(p3.path, '/path')
1665+
self.assertIs(p3.port, None)
1666+
p4 = urllib.parse.urlsplit('scheme://user@[0439:23af:2309::fae7:1234:192.0.2.146%test]/path?query')
1667+
self.assertEqual(p4.hostname, '0439:23af:2309::fae7:1234:192.0.2.146%test')
1668+
self.assertEqual(p4.username, 'user')
1669+
self.assertEqual(p4.path, '/path')
16651670

16661671
def test_port_casting_failure_message(self):
16671672
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
@@ -544,8 +544,8 @@ def _check_bracketed_netloc(netloc):
544544
# Valid bracketed hosts are defined in
545545
# https://www.rfc-editor.org/rfc/rfc3986#page-49 and https://url.spec.whatwg.org/
546546
def _check_bracketed_host(hostname):
547-
if hostname.startswith('v'):
548-
if not re.match(r"\Av[a-fA-F0-9]+\..+\z", hostname):
547+
if hostname.startswith(('v', 'V')):
548+
if not re.match(r"\A[vV][a-fA-F0-9]+\..+\z", hostname):
549549
raise ValueError(f"IPvFuture address is invalid")
550550
else:
551551
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)