Opened 13 years ago

Closed 13 years ago

Last modified 12 years ago

#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)

url_field.patch (2.2 KB ) - added by zigzag 13 years ago.

Download all attachments as: .zip

Change History (7)

by zigzag, 13 years ago

Attachment: url_field.patch added

comment:1 by zigzag, 13 years ago

Owner: zigzag removed

comment:2 by zigzag, 13 years ago

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.

comment:3 by Aymeric Augustin, 13 years ago

Triage Stage: UnreviewedAccepted

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 zigzag, 13 years ago

No, with my patch django.forms.fields.URLField.to_python will catch ValueError from urlparse.urlsplit and raise ValidationError.

Last edited 13 years ago by zigzag (previous) (diff)

comment:5 by zigzag, 13 years ago

Somebody, please answer me!

comment:6 by Chris Beaven, 13 years ago

Owner: set to Chris Beaven
Resolution: fixed
Status: newclosed

In [16752]:

Fixes #16664 -- URLField's to_python method fails with ValueError on some urls on python 2.7. Based on patch by zigzag.

Note: See TracTickets for help on using tickets.
Back to Top