From e0d3baa5225cc27ce6f068b873d2eaaed0ac19c1 Mon Sep 17 00:00:00 2001 From: Xyphuz Date: Tue, 10 Jan 2023 21:08:44 +0800 Subject: [PATCH] fix: ports start with colon cannot be parsed #38 --- compose_viz/parser.py | 2 +- tests/test_parse_file.py | 4 ++++ tests/ymls/ports/docker-compose.yml | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/compose_viz/parser.py b/compose_viz/parser.py index c67186c..64e8613 100644 --- a/compose_viz/parser.py +++ b/compose_viz/parser.py @@ -75,7 +75,7 @@ class Parser: container_port = str(int(port_data)) host_port = f"0.0.0.0:{container_port}" elif type(port_data) is str: - regex = r"(?P\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:)?((?P\d+(\-\d+)?):)?((?P\d+(\-\d+)?))?(/(?P\w+))?" # noqa: E501 + regex = r"((?P\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:)|:)?((?P\d+(\-\d+)?):)?((?P\d+(\-\d+)?))?(/(?P\w+))?" # noqa: E501 match = re.match(regex, port_data) if match: diff --git a/tests/test_parse_file.py b/tests/test_parse_file.py index 095c024..255d750 100644 --- a/tests/test_parse_file.py +++ b/tests/test_parse_file.py @@ -172,6 +172,10 @@ from compose_viz.parser import Parser container_port="6060", protocol=Protocol.udp, ), + Port( + host_port="0.0.0.0:7777", + container_port="7777", + ), Port( host_port="127.0.0.1:8080", container_port="80", diff --git a/tests/ymls/ports/docker-compose.yml b/tests/ymls/ports/docker-compose.yml index 642a975..725e10a 100644 --- a/tests/ymls/ports/docker-compose.yml +++ b/tests/ymls/ports/docker-compose.yml @@ -11,6 +11,7 @@ services: - "127.0.0.1:8001:8001" - "127.0.0.1:5000-5010:5000-5010" - "6060:6060/udp" + - ":7777" - target: 80 host_ip: 127.0.0.1 published: 8080