Opened 12 years ago

Closed 10 years ago

#19601 closed Uncategorized (duplicate)

urlize method fails with ValueError on urls with "[" on python 2.7

Reported by: EmilStenstrom Owned by: nobody
Component: Core (URLs) Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This issue has previously been reported when dealing with URLFields: https://code.djangoproject.com/ticket/16664

But it's also apparent in the urlize-filter (and probably in other places aswell)

from django.template.defaultfilters import urlize
urlize('http://[a')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files (x86)\python\lib\site-packages\django\template\defaultfilters.py", line 43, in _dec
    return func(*args, **kwargs)
  File "C:\Program Files (x86)\python\lib\site-packages\django\template\defaultfilters.py", line 334, in urlize
    return mark_safe(urlize_impl(value, nofollow=True, autoescape=autoescape))
  File "C:\Program Files (x86)\python\lib\site-packages\django\utils\functional.py", line 176, in wrapper
    return func(*args, **kwargs)
  File "C:\Program Files (x86)\python\lib\site-packages\django\utils\html.py", line 166, in urlize
    url = smart_urlquote(middle)
  File "C:\Program Files (x86)\python\lib\site-packages\django\utils\html.py", line 107, in smart_urlquote
    scheme, netloc, path, query, fragment = urlparse.urlsplit(url)
  File "C:\Program Files (x86)\python\lib\urlparse.py", line 183, in urlsplit
    raise ValueError("Invalid IPv6 URL")
ValueError: Invalid IPv6 URL

Change History (3)

comment:1 by Claude Paroz, 12 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #19070. Reopen if you can reproduce on Django 1.5.

comment:2 by Aurélien Bompard, 10 years ago

Resolution: duplicate
Status: closednew

This is with Python 2.7.5 and Django 1.5.6. It's not the exact same but but it's very related. Should I open a new ticket? (btw I'm not the original reporter)

>>> from django.template.defaultfilters import urlize
>>> urlize('http://a]a')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/django/template/defaultfilters.py", line 45, in _dec
    return func(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/django/template/defaultfilters.py", line 336, in urlize
    return mark_safe(urlize_impl(value, nofollow=True, autoescape=autoescape))
  File "/usr/lib/python2.7/site-packages/django/utils/functional.py", line 196, in wrapper
    return func(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/django/utils/html.py", line 210, in urlize
    url = smart_urlquote(middle)
  File "/usr/lib/python2.7/site-packages/django/utils/html.py", line 153, in smart_urlquote
    scheme, netloc, path, query, fragment = urlsplit(url)
  File "/usr/lib64/python2.7/urlparse.py", line 190, in urlsplit
    raise ValueError("Invalid IPv6 URL")
ValueError: Invalid IPv6 URL

comment:3 by Tim Graham, 10 years ago

Resolution: duplicate
Status: newclosed

The code you provided works in Django 1.6, we won't be backporting the fix to 1.5 as that branch is in security-fix only mode right now.

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