is_ipaddress shouldn't detect IPvFuture addresses
MODIFY
CHANGES.rst
CHANGES.rst
Changes
=======
+dev (master)
+------------
+
+* Change ``is_ipaddress`` to not detect IPvFuture addresses. (Pull #1583)
+
+
1.25.1 (2019-04-24)
-------------------

MODIFY
src/urllib3/util/ssl_.py
src/urllib3/util/ssl_.py
@@ -44,11 +44,10 @@ _const_compare_digest = getattr(hmac, 'compare_digest',
# Borrow rfc3986's regular expressions for IPv4
# and IPv6 addresses for use in is_ipaddress()
_IP_ADDRESS_REGEX = re.compile(
- r'^(?:%s|%s|%s|%s)$' % (
+ r'^(?:%s|%s|%s)$' % (
abnf_regexp.IPv4_RE,
abnf_regexp.IPv6_RE,
- abnf_regexp.IPv6_ADDRZ_RE,
- abnf_regexp.IPv_FUTURE_RE
+ abnf_regexp.IPv6_ADDRZ_RFC4007_RE
)
)
@@ -370,7 +369,8 @@ def ssl_wrap_socket(sock, keyfile=None, certfile=None, cert_reqs=None,
def is_ipaddress(hostname):
- """Detects whether the hostname given is an IP address.
+ """Detects whether the hostname given is an IPv4 or IPv6 address.
+ Also detects IPv6 addresses with Zone IDs.
:param str hostname: Hostname to examine.
:return: True if the hostname is an IP address, False otherwise.

MODIFY
test/test_ssl.py
test/test_ssl.py
@@ -5,11 +5,21 @@ from urllib3.exceptions import SNIMissingWarning
@pytest.mark.parametrize('addr', [
+ # IPv6
'::1',
'::',
+ 'FE80::8939:7684:D84b:a5A4%251',
+
+ # IPv4
'127.0.0.1',
'8.8.8.8',
- b'127.0.0.1'
+ b'127.0.0.1',
+
+ # IPv6 w/ Zone IDs
+ 'FE80::8939:7684:D84b:a5A4%251',
+ b'FE80::8939:7684:D84b:a5A4%251',
+ 'FE80::8939:7684:D84b:a5A4%19',
+ b'FE80::8939:7684:D84b:a5A4%19'
])
def test_is_ipaddress_true(addr):
assert ssl_.is_ipaddress(addr)
@@ -17,7 +27,9 @@ def test_is_ipaddress_true(addr):
@pytest.mark.parametrize('addr', [
'www.python.org',
- b'www.python.org'
+ b'www.python.org',
+ 'v2.sg.media-imdb.com',
+ b'v2.sg.media-imdb.com'
])
def test_is_ipaddress_false(addr):
assert not ssl_.is_ipaddress(addr)

is_ipaddress shouldn't detect IPvFuture addresses (#1583)