summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docker/utils/ports.py2
-rw-r--r--tests/unit/utils_test.py6
2 files changed, 7 insertions, 1 deletions
diff --git a/docker/utils/ports.py b/docker/utils/ports.py
index a50cc02..10b19d7 100644
--- a/docker/utils/ports.py
+++ b/docker/utils/ports.py
@@ -3,7 +3,7 @@ import re
PORT_SPEC = re.compile(
"^" # Match full string
"(" # External part
- r"((?P<host>[a-fA-F\d.:]+):)?" # Address
+ r"(\[?(?P<host>[a-fA-F\d.:]+)\]?:)?" # Address
r"(?P<ext>[\d]*)(-(?P<ext_end>[\d]+))?:" # External range
")?"
r"(?P<int>[\d]+)(-(?P<int_end>[\d]+))?" # Internal range
diff --git a/tests/unit/utils_test.py b/tests/unit/utils_test.py
index a53151c..0d6ff22 100644
--- a/tests/unit/utils_test.py
+++ b/tests/unit/utils_test.py
@@ -541,6 +541,12 @@ class PortsTest(unittest.TestCase):
assert internal_port == ["2000"]
assert external_port == [("2001:abcd:ef00::2", "1000")]
+ def test_split_port_with_ipv6_square_brackets_address(self):
+ internal_port, external_port = split_port(
+ "[2001:abcd:ef00::2]:1000:2000")
+ assert internal_port == ["2000"]
+ assert external_port == [("2001:abcd:ef00::2", "1000")]
+
def test_split_port_invalid(self):
with pytest.raises(ValueError):
split_port("0.0.0.0:1000:2000:tcp")