Skip to content

Commit 5631241

Browse files
committed
relax PORT_SPEC regex so it accept and ignore square brackets
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 55f405e commit 5631241

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

docker/utils/ports.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
PORT_SPEC = re.compile(
44
"^" # Match full string
55
"(" # External part
6-
r"((?P<host>[a-fA-F\d.:]+):)?" # Address
6+
r"(\[?(?P<host>[a-fA-F\d.:]+)\]?:)?" # Address
77
r"(?P<ext>[\d]*)(-(?P<ext_end>[\d]+))?:" # External range
88
")?"
99
r"(?P<int>[\d]+)(-(?P<int_end>[\d]+))?" # Internal range

tests/unit/utils_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,12 @@ def test_split_port_with_ipv6_address(self):
541541
assert internal_port == ["2000"]
542542
assert external_port == [("2001:abcd:ef00::2", "1000")]
543543

544+
def test_split_port_with_ipv6_square_brackets_address(self):
545+
internal_port, external_port = split_port(
546+
"[2001:abcd:ef00::2]:1000:2000")
547+
assert internal_port == ["2000"]
548+
assert external_port == [("2001:abcd:ef00::2", "1000")]
549+
544550
def test_split_port_invalid(self):
545551
with pytest.raises(ValueError):
546552
split_port("0.0.0.0:1000:2000:tcp")

0 commit comments

Comments
 (0)