mirror of
https://github.com/django/django.git
synced 2025-01-13 03:47:26 +00:00
fix the regex to help with form tests
This commit is contained in:
parent
9171d89be3
commit
6271cc9af0
@ -217,13 +217,14 @@ class EmailValidator:
|
||||
r'*"\Z)',
|
||||
re.IGNORECASE,
|
||||
)
|
||||
# Use DomainNameValidator patterns but remove the optional trailing dot
|
||||
domain_regex = _lazy_re_compile(
|
||||
r"^" + DomainNameValidator.hostname_re + DomainNameValidator.domain_re + r"\."
|
||||
r"(?!-)"
|
||||
r"(?:[a-z" + DomainNameValidator.ul + "-]{2,63}|xn--[a-z0-9]{1,59})"
|
||||
r"(?<!-)"
|
||||
r"$",
|
||||
# max length for domain name labels is 63 characters per RFC 1034
|
||||
r"((?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+)(?:[A-Z0-9-]{2,63}(?<!-))\Z",
|
||||
re.IGNORECASE,
|
||||
)
|
||||
domain_idn_regex = _lazy_re_compile(
|
||||
r"^" + DomainNameValidator.hostname_re + DomainNameValidator.domain_re +
|
||||
r"\." r"(?!-)" r"(?:[a-z" + DomainNameValidator.ul + "-]{2,63}|xn--[a-z0-9]{1,59})" r"(?<!-)" r"$",
|
||||
re.IGNORECASE,
|
||||
)
|
||||
literal_regex = _lazy_re_compile(
|
||||
@ -266,6 +267,11 @@ class EmailValidator:
|
||||
if self.domain_regex.match(domain_part):
|
||||
return True
|
||||
|
||||
# Try IDN validation if ASCII validation fails
|
||||
if not domain_part.isascii():
|
||||
if self.domain_idn_regex.match(domain_part):
|
||||
return True
|
||||
|
||||
literal_match = self.literal_regex.match(domain_part)
|
||||
if literal_match:
|
||||
ip_address = literal_match[1]
|
||||
|
Loading…
Reference in New Issue
Block a user