Skip to content

Commit c983950

Browse files
committed
Remove trailing slashes in result of utils.parse_host
Signed-off-by: Joffrey F <[email protected]>
1 parent 31afde6 commit c983950

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

docker/utils/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,8 @@ def parse_host(addr, is_win32=False, tls=False):
438438
"Bind address needs a port: {0}".format(addr))
439439

440440
if proto == "http+unix" or proto == 'npipe':
441-
return "{0}://{1}".format(proto, host)
442-
return "{0}://{1}:{2}{3}".format(proto, host, port, path)
441+
return "{0}://{1}".format(proto, host).rstrip('/')
442+
return "{0}://{1}:{2}{3}".format(proto, host, port, path).rstrip('/')
443443

444444

445445
def parse_devices(devices):

tests/unit/utils_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,11 @@ def test_parse_host_tls_tcp_proto(self):
522522
expected_result = 'https://myhost.docker.net:3348'
523523
assert parse_host(host_value, tls=True) == expected_result
524524

525+
def test_parse_host_trailing_slash(self):
526+
host_value = 'tcp://myhost.docker.net:2376/'
527+
expected_result = 'http://myhost.docker.net:2376'
528+
assert parse_host(host_value) == expected_result
529+
525530

526531
class ParseRepositoryTagTest(base.BaseTestCase):
527532
sha = 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'

0 commit comments

Comments
 (0)