From 54b3c364cbe8091768d342db5d167e174b6a416f Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Wed, 8 Mar 2017 16:13:56 -0800 Subject: [PATCH] Raise an error when passing an empty string to split_port Signed-off-by: Joffrey F --- docker/utils/ports.py | 2 ++ tests/integration/api_client_test.py | 2 -- tests/unit/utils_test.py | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docker/utils/ports.py b/docker/utils/ports.py index e2aeb8cc..3708958d 100644 --- a/docker/utils/ports.py +++ b/docker/utils/ports.py @@ -67,6 +67,8 @@ def split_port(port): if len(parts) == 1: internal_port, = parts + if not internal_port: + _raise_invalid_port(port) return to_port_range(internal_port), None if len(parts) == 2: external_port, internal_port = parts diff --git a/tests/integration/api_client_test.py b/tests/integration/api_client_test.py index d7873a85..cc641582 100644 --- a/tests/integration/api_client_test.py +++ b/tests/integration/api_client_test.py @@ -23,8 +23,6 @@ class InformationTest(BaseAPIIntegrationTest): self.assertIn('Containers', res) self.assertIn('Images', res) self.assertIn('Debug', res) - print(res) - self.fail() class LoadConfigTest(BaseAPIIntegrationTest): diff --git a/tests/unit/utils_test.py b/tests/unit/utils_test.py index ed84b3a1..4c3c3664 100644 --- a/tests/unit/utils_test.py +++ b/tests/unit/utils_test.py @@ -578,6 +578,9 @@ class PortsTest(unittest.TestCase): self.assertRaises(ValueError, lambda: split_port("localhost:80:")) + def test_split_port_empty_string(self): + self.assertRaises(ValueError, lambda: split_port("")) + def test_build_port_bindings_with_one_port(self): port_bindings = build_port_bindings(["127.0.0.1:1000:1000"]) self.assertEqual(port_bindings["1000"], [("127.0.0.1", "1000")])