diff options
| author | Chris Beaven <smileychris@gmail.com> | 2010-11-21 10:16:02 +0000 |
|---|---|---|
| committer | Chris Beaven <smileychris@gmail.com> | 2010-11-21 10:16:02 +0000 |
| commit | d04ffd72471a7b400ca8e3263effb87713c7dba1 (patch) | |
| tree | 24626ed93c62e6f79adcd098e9f8accf6b64a921 /django/forms/fields.py | |
| parent | 4a8519334d5649f242ea5f8b3a0547b26831129b (diff) | |
Fixes #13804 -- URLField validation failure for a url containing '://' on the path and no scheme. Backport of r14657
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14658 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/forms/fields.py')
| -rw-r--r-- | django/forms/fields.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py index 25ba5f5bdd..4584a72c7a 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -546,14 +546,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): |
