Kaydet (Commit) eba20084 authored tarafından Lei Gong's avatar Lei Gong

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: 's avatarLei Gong <xue177125184@gmail.com>
üst fa528243
......@@ -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")])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment