Allow underscores in broadlink hostnames (#35791)

* Allow underscores in hostnames

* Ignore case
This commit is contained in:
Felipe Martins Diel 2020-05-19 08:46:12 -03:00 committed by GitHub
parent 12ec476821
commit 2b38df2766
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -31,12 +31,12 @@ def data_packet(value):
def hostname(value):
"""Validate a hostname."""
host = str(value).lower()
host = str(value)
if len(host) > 253:
raise ValueError
if host[-1] == ".":
host = host[:-1]
allowed = re.compile(r"(?!-)[a-z\d-]{1,63}(?<!-)$")
allowed = re.compile(r"(?![_-])[a-z\d_-]{1,63}(?<![_-])$", flags=re.IGNORECASE)
if not all(allowed.match(elem) for elem in host.split(".")):
raise ValueError
return host