[Python-checkins] bpo-32323: urllib.parse.urlsplit() must not lowercase() IPv6 scope value (GH-4867) (#4959)
Andrew Svetlov
webhook-mailer at python.org
Thu Dec 21 07:54:48 EST 2017
https://github.com/python/cpython/commit/fdb148f949e3ae66036b75163ff68042d19cf0fc
commit: fdb148f949e3ae66036b75163ff68042d19cf0fc
branch: 3.6
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Andrew Svetlov <andrew.svetlov at gmail.com>
date: 2017-12-21T14:54:45+02:00
summary:
bpo-32323: urllib.parse.urlsplit() must not lowercase() IPv6 scope value (GH-4867) (#4959)
(cherry picked from commit fbd605151fcf2899b14575f4ddb9ce3c55e684ab)
files:
A Misc/NEWS.d/next/Library/2017-12-14-10-10-10.bpo-32323.ideco.rst
M Lib/test/test_urlparse.py
M Lib/urllib/parse.py
diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py
index e5f6130e4a0..ddee1c38d8b 100644
--- a/Lib/test/test_urlparse.py
+++ b/Lib/test/test_urlparse.py
@@ -520,6 +520,15 @@ def _encode(t):
self.assertEqual(result.url, defrag)
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):
url = "HTTP://WWW.PYTHON.ORG/doc/#frag"
p = urllib.parse.urlsplit(url)
diff --git a/Lib/urllib/parse.py b/Lib/urllib/parse.py
index 3cab2d13d5f..f959212b8bb 100644
--- a/Lib/urllib/parse.py
+++ b/Lib/urllib/parse.py
@@ -155,10 +155,12 @@ def password(self):
def hostname(self):
hostname = self._hostinfo[0]
if not hostname:
- hostname = None
- elif hostname is not None:
- hostname = hostname.lower()
- return hostname
+ return None
+ # Scoped IPv6 address may have zone info, which must not be lowercased
+ # like http://[fe80::822a:a8ff:fe49:470c%tESt]:1234/keys
+ separator = '%' if isinstance(hostname, str) else b'%'
+ hostname, percent, zone = hostname.partition(separator)
+ return hostname.lower() + percent + zone
@property
def port(self):
diff --git a/Misc/NEWS.d/next/Library/2017-12-14-10-10-10.bpo-32323.ideco.rst b/Misc/NEWS.d/next/Library/2017-12-14-10-10-10.bpo-32323.ideco.rst
new file mode 100644
index 00000000000..3077d7cdfef
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2017-12-14-10-10-10.bpo-32323.ideco.rst
@@ -0,0 +1,2 @@
+:func:`urllib.parse.urlsplit()` does not convert zone-id (scope) to lower case
+for scoped IPv6 addresses in hostnames now.
More information about the Python-checkins
mailing list