Ticket #6239: urlizetrunc.diff
File urlizetrunc.diff, 3.2 KB (added by , 17 years ago) |
---|
-
django/template/defaultfilters.py
254 254 urlize.needs_autoescape = True 255 255 urlize = stringfilter(urlize) 256 256 257 def urlizetrunc(value, limit ):257 def urlizetrunc(value, limit, autoescape=None): 258 258 """ 259 259 Converts URLs into clickable links, truncating URLs to the given character 260 260 limit, and adding 'rel=nofollow' attribute to discourage spamming. … … 262 262 Argument: Length to truncate URLs to. 263 263 """ 264 264 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)) 266 267 urlizetrunc.is_safe = True 268 urlizetrunc.needs_autoescape = True 267 269 urlizetrunc = stringfilter(urlizetrunc) 268 270 269 271 def wordcount(value): -
tests/regressiontests/templates/filters.py
108 108 'filter-urlize05': ('{% autoescape off %}{{ a|urlize }}{% endautoescape %}', {"a": "<script>alert('foo')</script>"}, "<script>alert('foo')</script>"), 109 109 'filter-urlize06': ('{{ a|urlize }}', {"a": "<script>alert('foo')</script>"}, '<script>alert('foo')</script>'), 110 110 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('"Safe" http://example.com?x=&y=')}, u'"Unsafe" <a href="http://example.com/x=&y=" rel="nofollow">http:...</a> "Safe" <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('"Safe" http://example.com?x=&y=')}, u'"Unsafe" <a href="http://example.com/x=&y=" rel="nofollow">http:...</a> "Safe" <a href="http://example.com?x=&y=" rel="nofollow">http:...</a>'), 113 113 114 114 'filter-wordcount01': ('{% autoescape off %}{{ a|wordcount }} {{ b|wordcount }}{% endautoescape %}', {"a": "a & b", "b": mark_safe("a & b")}, "3 3"), 115 115 'filter-wordcount02': ('{{ a|wordcount }} {{ b|wordcount }}', {"a": "a & b", "b": mark_safe("a & b")}, "3 3"),