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

* Improve port range parsing.

* Add changelog.
pull/62166/head
Felix Fontein 5 years ago committed by GitHub
parent 943888b955
commit d40ba28fb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

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

Loading…
Cancel
Save