Skip to content

Commit 80046f1

Browse files
committed
Raise an error when passing an empty string to split_port
Signed-off-by: Joffrey F <[email protected]>
1 parent 46093e2 commit 80046f1

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

docker/utils/ports.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ def split_port(port):
6767

6868
if len(parts) == 1:
6969
internal_port, = parts
70+
if not internal_port:
71+
_raise_invalid_port(port)
7072
return to_port_range(internal_port), None
7173
if len(parts) == 2:
7274
external_port, internal_port = parts

tests/integration/api_client_test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ def test_info(self):
2323
self.assertIn('Containers', res)
2424
self.assertIn('Images', res)
2525
self.assertIn('Debug', res)
26-
print(res)
27-
self.fail()
2826

2927

3028
class LoadConfigTest(BaseAPIIntegrationTest):

tests/unit/utils_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,9 @@ def test_with_no_container_port(self):
578578
self.assertRaises(ValueError,
579579
lambda: split_port("localhost:80:"))
580580

581+
def test_split_port_empty_string(self):
582+
self.assertRaises(ValueError, lambda: split_port(""))
583+
581584
def test_build_port_bindings_with_one_port(self):
582585
port_bindings = build_port_bindings(["127.0.0.1:1000:1000"])
583586
self.assertEqual(port_bindings["1000"], [("127.0.0.1", "1000")])

0 commit comments

Comments
 (0)