#3885 handle hyphens in domain name, enhance validation checks, linter updates

This commit is contained in:
Marcus R. Matos 2020-04-03 20:15:50 -05:00
parent 1039d09ed6
commit 2722f4fd76
2 changed files with 5 additions and 3 deletions

View File

@ -15,7 +15,9 @@ we'll go with the least restrictive rules while still providing a sanity check.
""" """
# label regex: in total between 4 and 255 chars, tld 2 to 63 chars, each label 1 to 63 chars # label regex: in total between 4 and 255 chars, tld 2 to 63 chars, each label 1 to 63 chars
_label_valid = re.compile(br"^(?=.{4,255}$)([A-Z0-9_-]([A-Z0-9_-]{0,61}[A-Z0-9_-])?\.){1,126}[A-Z0-9][A-Z0-9-]{0,61}[A-Z0-9]$", re.IGNORECASE) _label_valid = re.compile(
br"^(?=.{4,255}$)([A-Z0-9_-]([A-Z0-9_-]{0,61}[A-Z0-9_-])?\.)"
br"{1,126}[A-Z0-9][A-Z0-9-]{0,61}[A-Z0-9]$", re.IGNORECASE)
_host_valid = re.compile(br"[A-Z0-9\-_]{1,63}$", re.IGNORECASE) _host_valid = re.compile(br"[A-Z0-9\-_]{1,63}$", re.IGNORECASE)

View File

@ -36,7 +36,7 @@ def test_is_valid_host():
assert not check.is_valid_host(b'!.example.com') assert not check.is_valid_host(b'!.example.com')
# Every label must be between 1 and 63 chars # Every label must be between 1 and 63 chars
#assert not check.is_valid_host('.tld') assert not check.is_valid_host(b'.tld')
assert check.is_valid_host(b'x' * 1 + b'.tld') assert check.is_valid_host(b'x' * 1 + b'.tld')
assert check.is_valid_host(b'x' * 30 + b'.tld') assert check.is_valid_host(b'x' * 30 + b'.tld')
assert not check.is_valid_host(b'x' * 64 + b'.tld') assert not check.is_valid_host(b'x' * 64 + b'.tld')