1
0
mirror of https://github.com/django/django.git synced 2025-10-24 22:26:08 +00:00

Fixes #13804 -- URLField validation failure for a url containing '://' on the path and no scheme

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14657 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Chris Beaven
2010-11-21 10:08:28 +00:00
parent f6ead36969
commit b8a78804b5
2 changed files with 14 additions and 4 deletions

View File

@@ -581,14 +581,23 @@ class URLField(CharField):
def to_python(self, value):
if value:
if '://' not in value:
# If no URL scheme given, assume http://
value = u'http://%s' % value
url_fields = list(urlparse.urlsplit(value))
if not url_fields[0]:
# If no URL scheme given, assume http://
url_fields[0] = 'http'
if not url_fields[1]:
# Assume that if no domain is provided, that the path segment
# contains the domain.
url_fields[1] = url_fields[2]
url_fields[2] = ''
# Rebuild the url_fields list, since the domain segment may now
# contain the path too.
value = urlparse.urlunsplit(url_fields)
url_fields = list(urlparse.urlsplit(value))
if not url_fields[2]:
# the path portion may need to be added before query params
url_fields[2] = '/'
value = urlparse.urlunsplit(url_fields)
value = urlparse.urlunsplit(url_fields)
return super(URLField, self).to_python(value)
class BooleanField(Field):