Ticket #12027: 12027.diff

File 12027.diff, 1.5 KB (added by Tim Graham, 11 years ago)
  • django/core/validators.py

    diff --git a/django/core/validators.py b/django/core/validators.py
    index 796c57e..f07853e 100644
    a b class EmailValidator(object):  
    114114        if not self.user_regex.match(user_part):
    115115            raise ValidationError(self.message, code=self.code)
    116116
    117         if (not domain_part in self.domain_whitelist and
    118                 not self.domain_regex.match(domain_part)):
     117        def domain_is_invalid(domain):
     118            return not self.domain_regex.match(domain_part) or domain_part.endswith('.')
     119
     120        if domain_part not in self.domain_whitelist and domain_is_invalid(domain_part):
    119121            # Try for possible IDN domain-part
    120122            try:
    121123                domain_part = domain_part.encode('idna').decode('ascii')
    122                 if not self.domain_regex.match(domain_part):
     124                if domain_is_invalid(domain_part):
    123125                    raise ValidationError(self.message, code=self.code)
    124126                else:
    125127                    return
  • tests/validators/tests.py

    diff --git a/tests/validators/tests.py b/tests/validators/tests.py
    index 367bd43..e3f418e 100644
    a b TEST_DATA = (  
    5656    # Quoted-string format (CR not allowed)
    5757    (validate_email, '"\\\011"@here.com', None),
    5858    (validate_email, '"\\\012"@here.com', ValidationError),
     59    (validate_email, 'trailingdot@shouldfail.com.', ValidationError),
    5960
    6061    (validate_slug, 'slug-ok', None),
    6162    (validate_slug, 'longer-slug-still-ok', None),
Back to Top