Skip to content

Commit 33deb52

Browse files
max8899shin-
authored andcommitted
fix: Missing exception handling in split_port when no container port
"localhost:host_port:" case will raise TypeError exception directly Catch the "TypeError" and give proper error message * docker/utils/ports.py Signed-off-by: Lei Gong <[email protected]>
1 parent 2161ee1 commit 33deb52

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

docker/utils/ports.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,13 @@ def split_port(port):
8585
return internal_range, external_range
8686

8787
external_ip, external_port, internal_port = parts
88+
89+
if not internal_port:
90+
_raise_invalid_port(port)
91+
8892
internal_range = to_port_range(internal_port)
8993
external_range = to_port_range(external_port, len(internal_range) == 1)
94+
9095
if not external_range:
9196
external_range = [None] * len(internal_range)
9297

tests/unit/utils_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,10 @@ def test_host_only_with_colon(self):
574574
self.assertRaises(ValueError,
575575
lambda: split_port("localhost:"))
576576

577+
def test_with_no_container_port(self):
578+
self.assertRaises(ValueError,
579+
lambda: split_port("localhost:80:"))
580+
577581
def test_build_port_bindings_with_one_port(self):
578582
port_bindings = build_port_bindings(["127.0.0.1:1000:1000"])
579583
self.assertEqual(port_bindings["1000"], [("127.0.0.1", "1000")])

0 commit comments

Comments
 (0)