Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fiex #5331 -- Modified newforms URLField to prepend http:// if no pro…

…tocol is specified by the user. Thanks, SmileyChris.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6173 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 20ecbbd9e749f7abd0a7ffcc61b01cb874846817 1 parent 3358e2f
@freakboy3742 freakboy3742 authored
Showing with 12 additions and 8 deletions.
  1. +3 −0  django/newforms/fields.py
  2. +9 −8 tests/regressiontests/forms/tests.py
View
3  django/newforms/fields.py
@@ -416,6 +416,9 @@ def __init__(self, max_length=None, min_length=None, verify_exists=False,
self.user_agent = validator_user_agent
def clean(self, value):
+ # If no URL scheme given, assume http://
+ if value and '://' not in value:
+ value = u'http://%s' % value
value = super(URLField, self).clean(value)
if value == u'':
return value
View
17 tests/regressiontests/forms/tests.py
@@ -1623,10 +1623,6 @@
Traceback (most recent call last):
...
ValidationError: [u'Enter a valid URL.']
->>> f.clean('example.com')
-Traceback (most recent call last):
-...
-ValidationError: [u'Enter a valid URL.']
>>> f.clean('http://')
Traceback (most recent call last):
...
@@ -1657,10 +1653,6 @@
Traceback (most recent call last):
...
ValidationError: [u'Enter a valid URL.']
->>> f.clean('example.com')
-Traceback (most recent call last):
-...
-ValidationError: [u'Enter a valid URL.']
>>> f.clean('http://')
Traceback (most recent call last):
...
@@ -1714,6 +1706,15 @@
...
ValidationError: [u'Ensure this value has at most 20 characters (it has 37).']
+URLField should prepend 'http://' if no scheme was given
+>>> f = URLField(required=False)
+>>> f.clean('example.com')
+u'http://example.com'
+>>> f.clean('')
+u''
+>>> f.clean('https://example.com')
+u'https://example.com'
+
# BooleanField ################################################################
>>> f = BooleanField()
Please sign in to comment.
Something went wrong with that request. Please try again.