Kaydet (Commit) fbd60515 authored tarafından Коренберг Марк's avatar Коренберг Марк Kaydeden (comit) Andrew Svetlov

bpo-32323: urllib.parse.urlsplit() must not lowercase() IPv6 scope value (#4867)

üst a8d25a16
...@@ -520,6 +520,15 @@ class UrlParseTestCase(unittest.TestCase): ...@@ -520,6 +520,15 @@ class UrlParseTestCase(unittest.TestCase):
self.assertEqual(result.url, defrag) self.assertEqual(result.url, defrag)
self.assertEqual(result.fragment, frag) self.assertEqual(result.fragment, frag)
def test_urlsplit_scoped_IPv6(self):
p = urllib.parse.urlsplit('http://[FE80::822a:a8ff:fe49:470c%tESt]:1234')
self.assertEqual(p.hostname, "fe80::822a:a8ff:fe49:470c%tESt")
self.assertEqual(p.netloc, '[FE80::822a:a8ff:fe49:470c%tESt]:1234')
p = urllib.parse.urlsplit(b'http://[FE80::822a:a8ff:fe49:470c%tESt]:1234')
self.assertEqual(p.hostname, b"fe80::822a:a8ff:fe49:470c%tESt")
self.assertEqual(p.netloc, b'[FE80::822a:a8ff:fe49:470c%tESt]:1234')
def test_urlsplit_attributes(self): def test_urlsplit_attributes(self):
url = "HTTP://WWW.PYTHON.ORG/doc/#frag" url = "HTTP://WWW.PYTHON.ORG/doc/#frag"
p = urllib.parse.urlsplit(url) p = urllib.parse.urlsplit(url)
......
...@@ -155,10 +155,12 @@ class _NetlocResultMixinBase(object): ...@@ -155,10 +155,12 @@ class _NetlocResultMixinBase(object):
def hostname(self): def hostname(self):
hostname = self._hostinfo[0] hostname = self._hostinfo[0]
if not hostname: if not hostname:
hostname = None return None
elif hostname is not None: # Scoped IPv6 address may have zone info, which must not be lowercased
hostname = hostname.lower() # like http://[fe80::822a:a8ff:fe49:470c%tESt]:1234/keys
return hostname separator = '%' if isinstance(hostname, str) else b'%'
hostname, percent, zone = hostname.partition(separator)
return hostname.lower() + percent + zone
@property @property
def port(self): def port(self):
......
:func:`urllib.parse.urlsplit()` does not convert zone-id (scope) to lower case
for scoped IPv6 addresses in hostnames now.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment