text: Opened 6 years ago
  Closed 6 years ago
  Last modified 6 years ago
  #16664 closed Bug (fixed)
  URLField's to_python method fails with ValueError on some urls on python 2.7
  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) 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)
  Changed 6 years ago by
  comment:1 Changed 6 years ago by
  comment:2 Changed 6 years ago by
  comment:3 Changed 6 years ago by
  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 but it's true for Django's built-in form fields.
  comment:4 Changed 6 years ago by
  No, with my patch django.forms.fields.URLField.to_python will catch ValueError from urlparse.urlsplit and raise ValidationError.
  comment:5 Changed 6 years ago by
  Somebody, please answer me!
  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.