Skip to content

Commit 3566e7c

Browse files
authored
Merge pull request docker#1255 from docker/base_url_trailing_slash
Remove trailing slashes in result of utils.parse_host
2 parents 1ed2938 + 05f1060 commit 3566e7c

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
@@ -453,8 +453,8 @@ def parse_host(addr, is_win32=False, tls=False):
453453
"Bind address needs a port: {0}".format(addr))
454454

455455
if proto == "http+unix" or proto == 'npipe':
456-
return "{0}://{1}".format(proto, host)
457-
return "{0}://{1}:{2}{3}".format(proto, host, port, path)
456+
return "{0}://{1}".format(proto, host).rstrip('/')
457+
return "{0}://{1}:{2}{3}".format(proto, host, port, path).rstrip('/')
458458

459459

460460
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)