Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix and test for cleaning a non-string value in a URLField

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16747 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit fe88584589922c1a0e068f18c82fe1b17e437fcd 1 parent 699688d
Chris Beaven authored September 09, 2011
3  django/forms/fields.py
@@ -583,6 +583,7 @@ def __init__(self, max_length=None, min_length=None, verify_exists=False,
583 583
         self.validators.append(validators.URLValidator(verify_exists=verify_exists, validator_user_agent=validator_user_agent))
584 584
 
585 585
     def to_python(self, value):
  586
+        value = super(URLField, self).to_python(value)
586 587
         if value:
587 588
             url_fields = list(urlparse.urlsplit(value))
588 589
             if not url_fields[0]:
@@ -601,7 +602,7 @@ def to_python(self, value):
601 602
                 # the path portion may need to be added before query params
602 603
                 url_fields[2] = '/'
603 604
             value = urlparse.urlunsplit(url_fields)
604  
-        return super(URLField, self).to_python(value)
  605
+        return value
605 606
 
606 607
 class BooleanField(Field):
607 608
     widget = CheckboxInput
4  tests/regressiontests/forms/tests/fields.py
@@ -686,6 +686,10 @@ def test_urlfield_10(self):
686 686
         url = u'http://t\xfcr.djangoproject.com/'
687 687
         self.assertEqual(url, f.clean(url))
688 688
 
  689
+    def test_urlfield_not_string(self):
  690
+        f = URLField(required=False)
  691
+        self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 23)
  692
+
689 693
     # BooleanField ################################################################
690 694
 
691 695
     def test_booleanfield_1(self):

0 notes on commit fe88584

Please sign in to comment.
Something went wrong with that request. Please try again.