Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 10e6e0e

Browse files
author
Skip Montanaro
committed
Search from the end of the host/port combination to find the colon which
separates ip address from the port to accommodate ipv6 addresses.
1 parent 065a32f commit 10e6e0e

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

Lib/httplib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ def __init__(self, host, port=None, strict=None):
524524

525525
def _set_hostport(self, host, port):
526526
if port is None:
527-
i = host.find(':')
527+
i = host.rfind(':')
528528
if i >= 0:
529529
try:
530530
port = int(host[i+1:])

Lib/test/test_httplib.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ def _test():
118118
else:
119119
print "Expect InvalidURL"
120120

121+
for hp in ("[fe80::207:e9ff:fe9b]:8000", "www.python.org:80",
122+
"www.python.org"):
123+
try:
124+
h = httplib.HTTP(hp)
125+
except httplib.InvalidURL:
126+
print "InvalidURL raised erroneously"
127+
121128
# test response with multiple message headers with the same field name.
122129
text = ('HTTP/1.1 200 OK\r\n'
123130
'Set-Cookie: Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"\r\n'

0 commit comments

Comments
 (0)