Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions docker/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,23 @@ def parse_host(addr, is_win32=False, tls=False):

netloc = parsed_url.netloc
if proto in ('tcp', 'ssh'):
port = parsed_url.port or 0
if port <= 0:
try:
port = parsed_url.port
except ValueError as e:
raise errors.DockerException(
f'Invalid bind address format: {addr}'
) from e
if port is None:
if proto != 'ssh':
raise errors.DockerException(
f'Invalid bind address format: port is required: {addr}'
)
port = 22
netloc = f'{parsed_url.netloc}:{port}'
elif port <= 0:
raise errors.DockerException(
f'Invalid bind address format: port is required: {addr}'
)

if not parsed_url.hostname:
netloc = f'{DEFAULT_HTTP_HOST}:{port}'
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ def test_parse_host(self):
'unix:///sock/path#fragment',
'https://netloc:3333/path;params',
'ssh://:clearpassword@host:22',
'tcp://host:0',
'ssh://host:0',
'tcp://host:99999',
'tcp://host:notaport',
]

valid_hosts = {
Expand Down