Skip to content
Myr

Escape target attribute in the urlize function in utils.py. (#507)

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

authored by Sambhav Satija · committed by David Lord · parent c5a860c · Browse files · 2 files+13 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

2 files+13 added−2 removed

  • tests:+12 added−1 removed
  • other:+1 added−1 removed

2 files+13 added−2 removed

modified:jinja2/utils.py+1 added-1 removed
201 unmodified lines
202 or '')) or x203 words = _word_split_re.split(text_type(escape(text)))204 nofollow_attr = nofollow and ' rel="nofollow"' or ''205 if target is not None and isinstance(target, string_types):206 target_attr = ' target="%s"' % target206 target_attr = ' target="%s"' % escape(target)207 else:208 target_attr = ''209 for i, word in enumerate(words):210 match = _punctuation_re.match(word)
321 unmodified lines
modified:tests/test_utils.py+12 added-1 removed
12 unmodified lines
13import pytest1415import pickle1617from jinja2.utils import LRUCache, escape, object_type_repr17from jinja2.utils import LRUCache, escape, object_type_repr, urlize181920@pytest.mark.utils21@pytest.mark.lrucache
51 unmodified lines
73 escape(u"foo")74 escape(u"<foo>")75 counts.add(len(gc.get_objects()))76 assert len(counts) == 1, 'ouch, c extension seems to leak objects'777879@pytest.mark.utils80@pytest.mark.escapeUrlizeTarget81class TestEscapeUrlizeTarget():82 def test_escape_urlize_target(self):83 url = "http://example.org"84 target = "<script>"85 assert urlize(url, target=target) == ('<a href="http://example.org"'86 ' target="&lt;script&gt;">'87 'http://example.org</a>')