diff options
| author | Artem Mezhenin | 2014-02-13 20:14:47 +0400 | 
|---|---|---|
| committer | Artem Mezhenin | 2014-02-13 20:14:47 +0400 | 
| commit | dbd993d108b51bebbf9fd8d567d1c782cf941404 (patch) | |
| tree | d9a46fd4c552168817a8c3c27a7089c6d3d83004 /rest_framework | |
| parent | 08ec23268dbb4a40000b6c4bf877f5563a4ba57b (diff) | |
| download | django-rest-framework-dbd993d108b51bebbf9fd8d567d1c782cf941404.tar.bz2 | |
wrapper for smart_urlquote, issue #1386
Diffstat (limited to 'rest_framework')
| -rw-r--r-- | rest_framework/templatetags/rest_framework.py | 19 | 
1 files changed, 13 insertions, 6 deletions
diff --git a/rest_framework/templatetags/rest_framework.py b/rest_framework/templatetags/rest_framework.py index 0fcc5346..beb8c5b0 100644 --- a/rest_framework/templatetags/rest_framework.py +++ b/rest_framework/templatetags/rest_framework.py @@ -189,6 +189,17 @@ simple_url_2_re = re.compile(r'^www\.|^(?!http)\w[^@]+\.(com|edu|gov|int|mil|net  simple_email_re = re.compile(r'^\S+@\S+\.\S+$') +def smart_urlquote_wrapper(matched_url): +    """ +    Simple wrapper for smart_urlquote. ValueError("Invalid IPv6 URL") can +    be raised here, see issue #1386 +    """ +    try: +        return smart_urlquote(matched_url) +    except ValueError: +        return None + +  @register.filter  def urlize_quoted_links(text, trim_url_limit=None, nofollow=True, autoescape=True):      """ @@ -232,13 +243,9 @@ def urlize_quoted_links(text, trim_url_limit=None, nofollow=True, autoescape=Tru              url = None              nofollow_attr = ' rel="nofollow"' if nofollow else ''              if simple_url_re.match(middle): -                url = smart_urlquote(middle) +                url = smart_urlquote_wrapper(middle)              elif simple_url_2_re.match(middle): -                # ValueError("Invalid IPv6 URL") can be raised here, see issue #1386 -                try: -                    url = smart_urlquote('http://%s' % middle) -                except ValueError: -                    pass +                url = smart_urlquote_wrapper('http://%s' % middle)              elif not ':' in middle and simple_email_re.match(middle):                  local, domain = middle.rsplit('@', 1)                  try:  | 
