summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Beaven <smileychris@gmail.com>2011-09-09 22:32:38 +0000
committerChris Beaven <smileychris@gmail.com>2011-09-09 22:32:38 +0000
commitfe88584589922c1a0e068f18c82fe1b17e437fcd (patch)
tree1649dec9b4128ba8d883b63e4bcf33ee9808e87c
parent699688dc2cfad627c5d400c6bdb681c81e932bc0 (diff)
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
-rw-r--r--django/forms/fields.py3
-rw-r--r--tests/regressiontests/forms/tests/fields.py4
2 files changed, 6 insertions, 1 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py
index 113a5aab22..6fe25a9043 100644
--- a/django/forms/fields.py
+++ b/django/forms/fields.py
@@ -583,6 +583,7 @@ class URLField(CharField):
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 @@ class URLField(CharField):
# 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
diff --git a/tests/regressiontests/forms/tests/fields.py b/tests/regressiontests/forms/tests/fields.py
index e1b7fe00c6..7cbe2eaccf 100644
--- a/tests/regressiontests/forms/tests/fields.py
+++ b/tests/regressiontests/forms/tests/fields.py
@@ -686,6 +686,10 @@ class FieldsTests(SimpleTestCase):
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):