diff options
author | Nicolas De Loof <nicolas.deloof@gmail.com> | 2021-03-04 11:37:07 +0100 |
---|---|---|
committer | Nicolas De loof <nicolas.deloof@gmail.com> | 2021-03-10 11:25:18 +0100 |
commit | 563124163a5d092e954846121150d896ddca0836 (patch) | |
tree | 5f09690013af23904b1c9eff474d279790f098ad | |
parent | 55f405e04a91ddbbc26aa738bd3cb41bd28f8dbd (diff) | |
download | docker-py-563124163a5d092e954846121150d896ddca0836.tar.gz |
relax PORT_SPEC regex so it accept and ignore square brackets
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
-rw-r--r-- | docker/utils/ports.py | 2 | ||||
-rw-r--r-- | tests/unit/utils_test.py | 6 |
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") |