Browse Source

Single alpha characters for subdomains still identify as a valid hostname (#475)

pull/482/head
Chris Caron 3 years ago committed by GitHub
parent
commit
d248012d8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      apprise/utils.py
  2. 4
      test/test_utils.py

5
apprise/utils.py

@ -246,9 +246,10 @@ def is_hostname(hostname, ipv4=True, ipv6=True, underscore=True):
# being able to address services in other stacks, we also allow
# underscores in hostnames (if flag is set accordingly)
# - labels can not exceed 63 characters
# - allow single character alpha characters
allowed = re.compile(
r'^[a-z0-9][a-z0-9_-]{1,62}(?<![_-])$' if underscore else
r'^[a-z0-9][a-z0-9-]{1,62}(?<!-)$',
r'^([a-z0-9][a-z0-9_-]{1,62}|[a-z_-])(?<![_-])$' if underscore else
r'^([a-z0-9][a-z0-9-]{1,62}|[a-z-])(?<!-)$',
re.IGNORECASE,
)

4
test/test_utils.py

@ -605,6 +605,10 @@ def test_is_hostname():
assert utils.is_hostname(
'2001:0db8:85a3:0000:0000:8a2e:0370:7334', ipv6=False) is False
# Test hostnames with a single character hostname
assert utils.is_hostname(
'cloud.a.example.com', ipv4=False, ipv6=False) == 'cloud.a.example.com'
def test_is_ipaddr():
"""

Loading…
Cancel
Save