Code

Opened 3 years ago

Closed 3 years ago

Last modified 3 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: SmileyChris
Component: Forms Version: master
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 3 years ago.

Download all attachments as: .zip

Change History (7)

Changed 3 years ago by zigzag

comment:1 Changed 3 years ago by zigzag

  • Needs documentation unset
  • Needs tests unset
  • Owner zigzag deleted
  • Patch needs improvement unset

comment:2 Changed 3 years ago by zigzag

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 Changed 3 years ago by aaugustin

  • Triage Stage changed from Unreviewed to 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 Changed 3 years ago by zigzag

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

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

comment:5 Changed 3 years ago by zigzag

Somebody, please answer me!

comment:6 Changed 3 years ago by SmileyChris

  • Owner set to SmileyChris
  • Resolution set to fixed
  • Status changed from new to closed

In [16752]:

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.