mirror of https://github.com/docker/docker-py.git
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 <xue177125184@gmail.com>
This commit is contained in:
parent
fa52824363
commit
eba20084f6
|
@ -85,8 +85,13 @@ def split_port(port):
|
|||
return internal_range, external_range
|
||||
|
||||
external_ip, external_port, internal_port = parts
|
||||
|
||||
if not internal_port:
|
||||
_raise_invalid_port(port)
|
||||
|
||||
internal_range = to_port_range(internal_port)
|
||||
external_range = to_port_range(external_port, len(internal_range) == 1)
|
||||
|
||||
if not external_range:
|
||||
external_range = [None] * len(internal_range)
|
||||
|
||||
|
|
|
@ -574,6 +574,10 @@ class PortsTest(unittest.TestCase):
|
|||
self.assertRaises(ValueError,
|
||||
lambda: split_port("localhost:"))
|
||||
|
||||
def test_with_no_container_port(self):
|
||||
self.assertRaises(ValueError,
|
||||
lambda: split_port("localhost:80:"))
|
||||
|
||||
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")])
|
||||
|
|
Loading…
Reference in New Issue