Skip to content

Commit

Permalink
Fix and test for cleaning a non-string value in a URLField
Browse files Browse the repository at this point in the history
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16747 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
SmileyChris committed Sep 9, 2011
1 parent 699688d commit fe88584
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion django/forms/fields.py
Expand Up @@ -583,6 +583,7 @@ def __init__(self, max_length=None, min_length=None, verify_exists=False,
self.validators.append(validators.URLValidator(verify_exists=verify_exists, validator_user_agent=validator_user_agent)) self.validators.append(validators.URLValidator(verify_exists=verify_exists, validator_user_agent=validator_user_agent))


def to_python(self, value): def to_python(self, value):
value = super(URLField, self).to_python(value)
if value: if value:
url_fields = list(urlparse.urlsplit(value)) url_fields = list(urlparse.urlsplit(value))
if not url_fields[0]: if not url_fields[0]:
Expand All @@ -601,7 +602,7 @@ def to_python(self, value):
# the path portion may need to be added before query params # the path portion may need to be added before query params
url_fields[2] = '/' url_fields[2] = '/'
value = urlparse.urlunsplit(url_fields) value = urlparse.urlunsplit(url_fields)
return super(URLField, self).to_python(value) return value


class BooleanField(Field): class BooleanField(Field):
widget = CheckboxInput widget = CheckboxInput
Expand Down
4 changes: 4 additions & 0 deletions tests/regressiontests/forms/tests/fields.py
Expand Up @@ -686,6 +686,10 @@ def test_urlfield_10(self):
url = u'http://t\xfcr.djangoproject.com/' url = u'http://t\xfcr.djangoproject.com/'
self.assertEqual(url, f.clean(url)) 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 ################################################################ # BooleanField ################################################################


def test_booleanfield_1(self): def test_booleanfield_1(self):
Expand Down

0 comments on commit fe88584

Please sign in to comment.