Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[1.0.X] Fixed #9890 -- Modified the regex validation for email addres…

…ses to match RFC822/1035. Thanks to ozgur for the report, and kratorius for the patch.

Merge of 10573 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10576 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 5f20587fcb43cac9a65b72d44a201edf0666dd07 1 parent 33eca69
@freakboy3742 freakboy3742 authored
Showing with 27 additions and 6 deletions.
  1. +4 −4 django/forms/fields.py
  2. +23 −2 tests/regressiontests/forms/fields.py
View
8 django/forms/fields.py
@@ -256,8 +256,8 @@ def clean(self, value):
digits = len(digittuple)
if decimals > digits:
# We have leading zeros up to or past the decimal point. Count
- # everything past the decimal point as a digit. We do not count
- # 0 before the decimal point as a digit since that would mean
+ # everything past the decimal point as a digit. We do not count
+ # 0 before the decimal point as a digit since that would mean
# we would not allow max_digits = decimal_places.
digits = decimals
whole_digits = digits - decimals
@@ -421,7 +421,7 @@ def clean(self, value):
email_re = re.compile(
r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*" # dot-atom
r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*"' # quoted-string
- r')@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}$', re.IGNORECASE) # domain
+ r')@(?:[A-Z0-9]+(?:-*[A-Z0-9]+)*\.)+[A-Z]{2,6}$', re.IGNORECASE) # domain
class EmailField(RegexField):
default_error_messages = {
@@ -828,7 +828,7 @@ def __init__(self, path, match=None, recursive=False, required=True,
super(FilePathField, self).__init__(choices=(), required=required,
widget=widget, label=label, initial=initial, help_text=help_text,
*args, **kwargs)
-
+
if self.required:
self.choices = []
else:
View
25 tests/regressiontests/forms/fields.py
@@ -745,6 +745,27 @@
Traceback (most recent call last):
...
ValidationError: [u'Enter a valid e-mail address.']
+>>> f.clean('example@invalid-.com')
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a valid e-mail address.']
+>>> f.clean('example@-invalid.com')
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a valid e-mail address.']
+>>> f.clean('example@inv-.alid-.com')
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a valid e-mail address.']
+>>> f.clean('example@inv-.-alid.com')
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a valid e-mail address.']
+>>> f.clean('example@valid-----hyphens.com')
+u'example@valid-----hyphens.com'
+
+>>> f.clean('example@valid-with-hyphens.com')
+u'example@valid-with-hyphens.com'
>>> f = EmailField(required=False)
>>> f.clean('')
@@ -1104,7 +1125,7 @@
# TypedChoiceField ############################################################
-# TypedChoiceField is just like ChoiceField, except that coerced types will
+# TypedChoiceField is just like ChoiceField, except that coerced types will
# be returned:
>>> f = TypedChoiceField(choices=[(1, "+1"), (-1, "-1")], coerce=int)
>>> f.clean('1')
@@ -1122,7 +1143,7 @@
# This can also cause weirdness: be careful (bool(-1) == True, remember)
>>> f.coerce = bool
->>> f.clean('-1')
+>>> f.clean('-1')
True
# Even more weirdness: if you have a valid choice but your coercion function
Please sign in to comment.
Something went wrong with that request. Please try again.