Skip to content

Commit 50a6071

Browse files
committed
split_port should not break when passed a non-string argument
Signed-off-by: Joffrey F <joffrey@docker.com>
1 parent 706e2ca commit 50a6071

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

docker/utils/ports.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def port_range(start, end, proto, randomly_available_port=False):
5454

5555

5656
def split_port(port):
57+
port = str(port)
5758
match = PORT_SPEC.match(port)
5859
if match is None:
5960
_raise_invalid_port(port)

tests/unit/utils_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,9 @@ def test_with_no_container_port(self):
587587
def test_split_port_empty_string(self):
588588
self.assertRaises(ValueError, lambda: split_port(""))
589589

590+
def test_split_port_non_string(self):
591+
assert split_port(1243) == (['1243'], None)
592+
590593
def test_build_port_bindings_with_one_port(self):
591594
port_bindings = build_port_bindings(["127.0.0.1:1000:1000"])
592595
self.assertEqual(port_bindings["1000"], [("127.0.0.1", "1000")])

0 commit comments

Comments
 (0)