Ticket #6239: urlizetrunc.diff

File urlizetrunc.diff, 3.2 KB (added by Chris Beaven, 17 years ago)

fix inc. modified tests

  • django/template/defaultfilters.py

     
    254254urlize.needs_autoescape = True
    255255urlize = stringfilter(urlize)
    256256
    257 def urlizetrunc(value, limit):
     257def urlizetrunc(value, limit, autoescape=None):
    258258    """
    259259    Converts URLs into clickable links, truncating URLs to the given character
    260260    limit, and adding 'rel=nofollow' attribute to discourage spamming.
     
    262262    Argument: Length to truncate URLs to.
    263263    """
    264264    from django.utils.html import urlize
    265     return mark_safe(urlize(value, trim_url_limit=int(limit), nofollow=True))
     265    return mark_safe(urlize(value, trim_url_limit=int(limit), nofollow=True,
     266                            autoescape=autoescape))
    266267urlizetrunc.is_safe = True
     268urlizetrunc.needs_autoescape = True
    267269urlizetrunc = stringfilter(urlizetrunc)
    268270
    269271def wordcount(value):
  • tests/regressiontests/templates/filters.py

     
    108108        'filter-urlize05': ('{% autoescape off %}{{ a|urlize }}{% endautoescape %}', {"a": "<script>alert('foo')</script>"}, "<script>alert('foo')</script>"),
    109109        'filter-urlize06': ('{{ a|urlize }}', {"a": "<script>alert('foo')</script>"}, '&lt;script&gt;alert(&#39;foo&#39;)&lt;/script&gt;'),
    110110
    111         'filter-urlizetrunc01': ('{% autoescape off %}{{ a|urlizetrunc:"8" }} {{ b|urlizetrunc:"8" }}{% endautoescape %}', {"a": "http://example.com/x=&y=", "b": mark_safe("http://example.com?x=&y=")}, u'<a href="http://example.com/x=&y=" rel="nofollow">http:...</a> <a href="http://example.com?x=&y=" rel="nofollow">http:...</a>'),
    112         'filter-urlizetrunc02': ('{{ a|urlizetrunc:"8" }} {{ b|urlizetrunc:"8" }}', {"a": "http://example.com/x=&y=", "b": mark_safe("http://example.com?x=&y=")}, u'<a href="http://example.com/x=&y=" rel="nofollow">http:...</a> <a href="http://example.com?x=&y=" rel="nofollow">http:...</a>'),
     111        'filter-urlizetrunc01': ('{% autoescape off %}{{ a|urlizetrunc:"8" }} {{ b|urlizetrunc:"8" }}{% endautoescape %}', {"a": '"Unsafe" http://example.com/x=&y=', "b": mark_safe('&quot;Safe&quot; http://example.com?x=&y=')}, u'"Unsafe" <a href="http://example.com/x=&y=" rel="nofollow">http:...</a> &quot;Safe&quot; <a href="http://example.com?x=&y=" rel="nofollow">http:...</a>'),
     112        'filter-urlizetrunc02': ('{{ a|urlizetrunc:"8" }} {{ b|urlizetrunc:"8" }}', {"a": '"Unsafe" http://example.com/x=&y=', "b": mark_safe('&quot;Safe&quot; http://example.com?x=&y=')}, u'&quot;Unsafe&quot; <a href="http://example.com/x=&y=" rel="nofollow">http:...</a> &quot;Safe&quot; <a href="http://example.com?x=&y=" rel="nofollow">http:...</a>'),
    113113
    114114        'filter-wordcount01': ('{% autoescape off %}{{ a|wordcount }} {{ b|wordcount }}{% endautoescape %}', {"a": "a & b", "b": mark_safe("a &amp; b")}, "3 3"),
    115115        'filter-wordcount02': ('{{ a|wordcount }} {{ b|wordcount }}', {"a": "a & b", "b": mark_safe("a &amp; b")}, "3 3"),
Back to Top