From 45877b1c237f8e8eb2aa345a9333dae38ce7acc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Leyendecker?= Date: Thu, 1 Dec 2022 12:31:30 +0000 Subject: [PATCH] Avoid stripping characters in volume names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Loïc Leyendecker --- docker/models/containers.py | 4 +++- tests/unit/models_containers_test.py | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docker/models/containers.py b/docker/models/containers.py index 4508557d28..61d048c4fe 100644 --- a/docker/models/containers.py +++ b/docker/models/containers.py @@ -1147,8 +1147,10 @@ def _host_volume_from_bind(bind): bits = rest.split(':', 1) if len(bits) == 1 or bits[1] in ('ro', 'rw'): return drive + bits[0] + elif bits[1].endswith(':ro') or bits[1].endswith(':rw'): + return bits[1][:-3] else: - return bits[1].rstrip(':ro').rstrip(':rw') + return bits[1] ExecResult = namedtuple('ExecResult', 'exit_code,output') diff --git a/tests/unit/models_containers_test.py b/tests/unit/models_containers_test.py index 101708ebb7..51f0018029 100644 --- a/tests/unit/models_containers_test.py +++ b/tests/unit/models_containers_test.py @@ -103,7 +103,7 @@ def test_create_container_args(self): volumes=[ '/home/user1/:/mnt/vol2', '/var/www:/mnt/vol1:ro', - 'volumename:/mnt/vol3', + 'volumename:/mnt/vol3r', '/volumewithnohostpath', '/anothervolumewithnohostpath:ro', 'C:\\windows\\path:D:\\hello\\world:rw' @@ -123,7 +123,7 @@ def test_create_container_args(self): 'Binds': [ '/home/user1/:/mnt/vol2', '/var/www:/mnt/vol1:ro', - 'volumename:/mnt/vol3', + 'volumename:/mnt/vol3r', '/volumewithnohostpath', '/anothervolumewithnohostpath:ro', 'C:\\windows\\path:D:\\hello\\world:rw' @@ -198,7 +198,7 @@ def test_create_container_args(self): volumes=[ '/mnt/vol2', '/mnt/vol1', - '/mnt/vol3', + '/mnt/vol3r', '/volumewithnohostpath', '/anothervolumewithnohostpath', 'D:\\hello\\world'