docker_container: improve port range parsing error behavior (#61740)

* Improve port range parsing.

* Add changelog.
This commit is contained in:
Felix Fontein 2019-09-08 20:30:18 +02:00 committed by GitHub
parent 943888b955
commit d40ba28fb4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- "docker_container - improve error behavior when parsing port ranges fails."

View file

@ -1078,12 +1078,18 @@ def parse_port_range(range_or_port, client):
Returns a list of integers for each port in the list.
'''
if '-' in range_or_port:
start, end = [int(port) for port in range_or_port.split('-')]
try:
start, end = [int(port) for port in range_or_port.split('-')]
except Exception:
client.fail('Invalid port range: "{0}"'.format(range_or_port))
if end < start:
client.fail('Invalid port range: {0}'.format(range_or_port))
client.fail('Invalid port range: "{0}"'.format(range_or_port))
return list(range(start, end + 1))
else:
return [int(range_or_port)]
try:
return [int(range_or_port)]
except Exception:
client.fail('Invalid port: "{0}"'.format(range_or_port))
def split_colon_ipv6(text, client):