diff options
| author | Honza Král <honza.kral@gmail.com> | 2009-09-11 22:12:30 +0000 |
|---|---|---|
| committer | Honza Král <honza.kral@gmail.com> | 2009-09-11 22:12:30 +0000 |
| commit | 83a3588ff712d5fe44e9692f5cb6a1d020f3ab2f (patch) | |
| tree | 1c24fa60c9b110adb150231cdb69cd731f208af5 /django/forms/fields.py | |
| parent | 9222091de8fa2fcb4fedd74ac99b65c88d295135 (diff) | |
[soc2009/model-validation] Fixed #11826 django.forms.fields.URLField rejects valid URLs with no abs_path component
Thanks wam
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/model-validation@11525 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/forms/fields.py')
| -rw-r--r-- | django/forms/fields.py | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py index 4b4594a5c2..3197260fb6 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -551,12 +551,15 @@ class URLField(CharField): self.validators.append(validators.URLValidator(verify_exists=verify_exists, validator_user_agent=validator_user_agent)) def to_python(self, value): - # If no URL scheme given, assume http:// - if value and '://' not in value: - value = u'http://%s' % value - # If no URL path given, assume / - if value and not urlparse.urlsplit(value)[2]: - 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[2]: + # 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) class BooleanField(Field): |
