fix: ports start with colon cannot be parsed #38

This commit is contained in:
Xyphuz 2023-01-10 21:08:44 +08:00
parent 1b516a12e1
commit e0d3baa522
3 changed files with 6 additions and 1 deletions

View file

@ -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<host_ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:)?((?P<host_port>\d+(\-\d+)?):)?((?P<container_port>\d+(\-\d+)?))?(/(?P<protocol>\w+))?" # noqa: E501
regex = r"((?P<host_ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:)|:)?((?P<host_port>\d+(\-\d+)?):)?((?P<container_port>\d+(\-\d+)?))?(/(?P<protocol>\w+))?" # noqa: E501
match = re.match(regex, port_data)
if match:

View file

@ -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",

View file

@ -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