Author: russellm
Date: 2009-04-16 09:24:27 -0500 (Thu, 16 Apr 2009)
New Revision: 10573

Modified:
   django/trunk/django/forms/fields.py
   django/trunk/tests/regressiontests/forms/fields.py
Log:
Fixed #9890 -- Modified the regex validation for email addresses to match 
RFC822/1035. Thanks to ozgur for the report, and kratorius for the patch.

Modified: django/trunk/django/forms/fields.py
===================================================================
--- django/trunk/django/forms/fields.py 2009-04-16 14:16:16 UTC (rev 10572)
+++ django/trunk/django/forms/fields.py 2009-04-16 14:24:27 UTC (rev 10573)
@@ -256,8 +256,8 @@
         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
@@ -283,7 +283,7 @@
 )
 
 class DateField(Field):
-    widget = DateInput 
+    widget = DateInput
     default_error_messages = {
         'invalid': _(u'Enter a valid date.'),
     }
@@ -422,7 +422,7 @@
 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 = {
@@ -829,7 +829,7 @@
         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:

Modified: django/trunk/tests/regressiontests/forms/fields.py
===================================================================
--- django/trunk/tests/regressiontests/forms/fields.py  2009-04-16 14:16:16 UTC 
(rev 10572)
+++ django/trunk/tests/regressiontests/forms/fields.py  2009-04-16 14:24:27 UTC 
(rev 10573)
@@ -745,7 +745,28 @@
 Traceback (most recent call last):
 ...
 ValidationError: [u'Enter a valid e-mail address.']
+>>> f.clean('[email protected]')
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a valid e-mail address.']
+>>> f.clean('[email protected]')
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a valid e-mail address.']
+>>> f.clean('[email protected]')
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a valid e-mail address.']
+>>> f.clean('[email protected]')
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a valid e-mail address.']
+>>> f.clean('[email protected]')
+u'[email protected]'
 
+>>> f.clean('[email protected]')
+u'[email protected]'
+
 >>> f = EmailField(required=False)
 >>> f.clean('')
 u''
@@ -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


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to