mirror of https://github.com/django/django.git
[1.6.x] Fixed #22579 -- Corrected validation for email to reject trailing slash
Backport of 424fe76349
from master.
This commit is contained in:
parent
4b49cbfae4
commit
50a289d05f
|
@ -42,7 +42,7 @@ class RegexValidator(object):
|
|||
class URLValidator(RegexValidator):
|
||||
regex = re.compile(
|
||||
r'^(?:http|ftp)s?://' # http:// or https://
|
||||
r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' # domain...
|
||||
r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}(?<!-)\.?)|' # domain...
|
||||
r'localhost|' # localhost...
|
||||
r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|' # ...or ipv4
|
||||
r'\[?[A-F0-9]*:[A-F0-9:]+\]?)' # ...or ipv6
|
||||
|
@ -85,7 +85,7 @@ class EmailValidator(object):
|
|||
r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-\011\013\014\016-\177])*"$)', # quoted-string
|
||||
re.IGNORECASE)
|
||||
domain_regex = re.compile(
|
||||
r'(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}|[A-Z0-9-]{2,})\.?$' # domain
|
||||
r'(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}|[A-Z0-9-]{2,}(?<!-))$'
|
||||
# literal form, ipv4 address (SMTP 4.1.3)
|
||||
r'|^\[(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\]$',
|
||||
re.IGNORECASE)
|
||||
|
|
|
@ -44,6 +44,7 @@ TEST_DATA = (
|
|||
(validate_email, 'email@127.0.0.1', ValidationError),
|
||||
(validate_email, 'example@invalid-.com', ValidationError),
|
||||
(validate_email, 'example@-invalid.com', ValidationError),
|
||||
(validate_email, 'example@invalid.com-', ValidationError),
|
||||
(validate_email, 'example@inv-.alid-.com', ValidationError),
|
||||
(validate_email, 'example@inv-.-alid.com', ValidationError),
|
||||
(validate_email, 'test@example.com\n\n<script src="x.js">', ValidationError),
|
||||
|
@ -153,6 +154,7 @@ TEST_DATA = (
|
|||
(URLValidator(), 'http://.com', ValidationError),
|
||||
(URLValidator(), 'http://invalid-.com', ValidationError),
|
||||
(URLValidator(), 'http://-invalid.com', ValidationError),
|
||||
(URLValidator(), 'http://invalid.com-', ValidationError),
|
||||
(URLValidator(), 'http://inv-.alid-.com', ValidationError),
|
||||
(URLValidator(), 'http://inv-.-alid.com', ValidationError),
|
||||
|
||||
|
|
Loading…
Reference in New Issue