Skip to content

split_port() does not properly handle ":80" or "127.0.0.1:" properly #726

@mark-adams

Description

@mark-adams

Initially reported as docker/compose#1887

Example:

    def test_port_only_with_colon(self):
        self.assertRaises(ValueError,
                          lambda: split_port(":80"))

    def test_host_only_with_colon(self):
        self.assertRaises(ValueError,
                          lambda: split_port("localhost:"))

Results:

======================================================================
ERROR: test_host_only_with_colon (__main__.UtilsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests/utils_test.py", line 428, in test_host_only_with_colon
    lambda: split_port("localhost:"))
  File "/usr/lib/python2.7/unittest/case.py", line 473, in assertRaises
    callableObj(*args, **kwargs)
  File "tests/utils_test.py", line 428, in <lambda>
    lambda: split_port("localhost:"))
  File "/home/mark/Projects/docker-py/docker/utils/ports/ports.py", line 77, in split_port
    if len(internal_range) != len(external_range):
TypeError: object of type 'NoneType' has no len()

======================================================================
ERROR: test_port_only_with_colon (__main__.UtilsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests/utils_test.py", line 424, in test_port_only_with_colon
    lambda: split_port(":80"))
  File "/usr/lib/python2.7/unittest/case.py", line 473, in assertRaises
    callableObj(*args, **kwargs)
  File "tests/utils_test.py", line 424, in <lambda>
    lambda: split_port(":80"))
  File "/home/mark/Projects/docker-py/docker/utils/ports/ports.py", line 77, in split_port
    if len(internal_range) != len(external_range):
TypeError: object of type 'NoneType' has no len()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions