Skip to content

Commit

Permalink
relax PORT_SPEC regex so it accept and ignore square brackets
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Mar 4, 2021
1 parent 55f405e commit be49c28
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docker/utils/ports.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,12 @@ def test_split_port_with_ipv6_address(self):
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")
Expand Down

0 comments on commit be49c28

Please sign in to comment.