#16664 closed Bug (fixed)
URLField's to_python method fails with ValueError on some urls on python 2.7
Reported by: | zigzag | Owned by: | Chris Beaven |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
This happens cause an urlparse libraries of python 2.7 and <2.7 are very different - in 2.7 python urlparse on invalid IPv6 url (that may be http://[1080:0:0:0:8:800:200C:417A]/index.html - see http://www.ietf.org/rfc/rfc2732.txt) fails with ValueError, but urlparse at py < 2.7 never raises an exception. For example,
import urlparse print urlparse.urlsplit('http://[a')
will print SplitResult(scheme='http', netloc='[a', path=, query=, fragment='') on python 2.6 and will raise ValueError("Invalid IPv6 URL") on python 2.7
Attachments (1)
Change History (7)
by , 13 years ago
Attachment: | url_field.patch added |
---|
comment:1 by , 13 years ago
Owner: | removed |
---|
comment:2 by , 13 years ago
comment:3 by , 13 years ago
Triage Stage: | Unreviewed → Accepted |
---|
zigzag, your report doesn't mention Django at all — I nearly closed the ticket as unrelated to Django! :)
Given the patch, if I understand correctly, the bug is that, since python 2.7, django.forms.fields.URLField.to_python
can raise ValueError
.
But a form field's to_python
method shouldn't raise any exception other than ValidationError
.
This rule isn't written explicitly in https://docs.djangoproject.com/en/1.3/ref/forms/validation/ but it's true for Django's built-in form fields.
comment:4 by , 13 years ago
No, with my patch django.forms.fields.URLField.to_python will catch ValueError from urlparse.urlsplit and raise ValidationError.
I've created a patch for this bug, but it doesn't cover processing ipv6 urls, it only catch ValueError exception from urlparse's urlsplit ibrary.