Skip to content
Myr

Fixed an escaping bug in urlize

Before adoption: this commit came in with the history the project adopted, so no landing records it.

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent ba6e25a · Browse files · 4 files+9 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+9 added−2 removed

  • tests:+5 added−0 removed
  • other:+4 added−2 removed

4 files+9 added−2 removed

modified:jinja2/filters.py+1 added-1 removed
320 unmodified lines
321322 {{ mytext|urlize(40, true) }}323 links are shortened to 40 chars and defined with rel="nofollow"324 """325 rv = urlize(soft_unicode(value), trim_url_limit, nofollow)325 rv = urlize(value, trim_url_limit, nofollow)326 if environment.autoescape:327 rv = Markup(rv)328 return rv329
386 unmodified lines
modified:jinja2/utils.py+1 added-1 removed
216 unmodified lines
217 """218 trim_url = lambda x, limit=trim_url_limit: limit is not None \219 and (x[:limit] + (len(x) >=limit and '...'220 or '')) or x221 words = _word_split_re.split(text)221 words = _word_split_re.split(unicode(escape(text)))222 nofollow_attr = nofollow and ' rel="nofollow"' or ''223 for i, word in enumerate(words):224 match = _punctuation_re.match(word)225 if match:
523 unmodified lines
modified:tests/test_old_bugs.py+5 added
26 unmodified lines
27 '[[{% block title %}title{% endblock %}]]'28 '{% for item in [1, 2, 3] %}({{ item }}){% endfor %}')29 assert t.render(expr=False) == '[[title]](1)(2)(3)'30 assert t.render(expr=True) == '((title))'313233def test_urlize_filter_escaping(env):34 tmpl = env.from_string('{{ "http://www.example.org/<foo"|urlize }}')35 assert tmpl.render() == '<a href="http://www.example.org/&lt;foo">http://www.example.org/&lt;foo</a>'
modified:CHANGES+2 added
42 unmodified lines
4344- added a `compile_expression` method to the environment that allows compiling45 of Jinja expressions into callable Python objects.4647- fixed an escaping bug in urlize4849Version 2.050-----------51(codename jinjavitus, released on July 17th 2008)52
32 unmodified lines