Author: SmileyChris
Date: 2011-09-09 15:32:38 -0700 (Fri, 09 Sep 2011)
New Revision: 16747

Modified:
   django/trunk/django/forms/fields.py
   django/trunk/tests/regressiontests/forms/tests/fields.py
Log:
Fix and test for cleaning a non-string value in a URLField

Modified: django/trunk/django/forms/fields.py
===================================================================
--- django/trunk/django/forms/fields.py 2011-09-09 22:29:21 UTC (rev 16746)
+++ django/trunk/django/forms/fields.py 2011-09-09 22:32:38 UTC (rev 16747)
@@ -583,6 +583,7 @@
         
self.validators.append(validators.URLValidator(verify_exists=verify_exists, 
validator_user_agent=validator_user_agent))
 
     def to_python(self, value):
+        value = super(URLField, self).to_python(value)
         if value:
             url_fields = list(urlparse.urlsplit(value))
             if not url_fields[0]:
@@ -601,7 +602,7 @@
                 # the path portion may need to be added before query params
                 url_fields[2] = '/'
             value = urlparse.urlunsplit(url_fields)
-        return super(URLField, self).to_python(value)
+        return value
 
 class BooleanField(Field):
     widget = CheckboxInput

Modified: django/trunk/tests/regressiontests/forms/tests/fields.py
===================================================================
--- django/trunk/tests/regressiontests/forms/tests/fields.py    2011-09-09 
22:29:21 UTC (rev 16746)
+++ django/trunk/tests/regressiontests/forms/tests/fields.py    2011-09-09 
22:32:38 UTC (rev 16747)
@@ -686,6 +686,10 @@
         url = u'http://t\xfcr.djangoproject.com/'
         self.assertEqual(url, f.clean(url))
 
+    def test_urlfield_not_string(self):
+        f = URLField(required=False)
+        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", 
f.clean, 23)
+
     # BooleanField 
################################################################
 
     def test_booleanfield_1(self):

-- 
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