Fix transport URL parsing bug
Handle e.g. foo://u:p@/bar. Right now we get:
IndexError: string index out of range
from:
if hostname[0] == '[':
Change-Id: I0bccebb14ad1d37862955e8988d160240bd1cf6d
This commit is contained in:
@@ -386,7 +386,9 @@ class TransportURL(object):
|
|||||||
if ':' in username:
|
if ':' in username:
|
||||||
username, password = username.split(':', 1)
|
username, password = username.split(':', 1)
|
||||||
|
|
||||||
if hostname[0] == '[':
|
if not hostname:
|
||||||
|
hostname = None
|
||||||
|
elif hostname.startswith('['):
|
||||||
# Find the closing ']' and extract the hostname
|
# Find the closing ']' and extract the hostname
|
||||||
host_end = hostname.find(']')
|
host_end = hostname.find(']')
|
||||||
if host_end < 0:
|
if host_end < 0:
|
||||||
|
|||||||
@@ -78,6 +78,13 @@ class TestParseURL(test_utils.BaseTestCase):
|
|||||||
dict(host='host', port=1234,
|
dict(host='host', port=1234,
|
||||||
username='u', password='p'),
|
username='u', password='p'),
|
||||||
]))),
|
]))),
|
||||||
|
('creds_no_host',
|
||||||
|
dict(url='foo://u:p@/bar',
|
||||||
|
expect=dict(transport='foo',
|
||||||
|
virtual_host='bar',
|
||||||
|
hosts=[
|
||||||
|
dict(username='u', password='p'),
|
||||||
|
]))),
|
||||||
('multi_host',
|
('multi_host',
|
||||||
dict(url='foo://u:p@host1:1234,host2:4321/bar',
|
dict(url='foo://u:p@host1:1234,host2:4321/bar',
|
||||||
expect=dict(transport='foo',
|
expect=dict(transport='foo',
|
||||||
|
|||||||
Reference in New Issue
Block a user