Skip to content
Myr

Merge pull request #718 from ayalash/issue_709

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

Make tojson always safe (fix #709)

authored by David Lord · committed by GitHub · parents 5b335b7, 8634697 · Browse files · 3 files+14 added−3 removed
This commit

State

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

Diff stats

3 files+14 added−3 removed

  • tests:+3 added−2 removed
  • other:+11 added−1 removed

3 files+14 added−3 removed

modified:jinja2/utils.py+1 added-1 removed
565 unmodified lines
566 .replace(u'<', u'\\u003c') \567 .replace(u'>', u'\\u003e') \568 .replace(u'&', u'\\u0026') \569 .replace(u"'", u'\\u0027')570 return rv570 return Markup(rv)571572573@implements_iterator574class Cycler(object):
50 unmodified lines
modified:tests/test_filters.py+3 added-2 removed
578 unmodified lines
579580 def test_json_dump(self):581 env = Environment(autoescape=True)582 t = env.from_string('{{ x|tojson }}')583 assert t.render(x={'foo': 'bar'}) == '{&#34;foo&#34;: &#34;bar&#34;}'584 assert t.render(x='"bar\'') == r'&#34;\&#34;bar\u0027&#34;'583 assert t.render(x={'foo': 'bar'}) == '{"foo": "bar"}'584 assert t.render(x='"ba&r\'') == r'"\"ba\u0026r\u0027"'585 assert t.render(x='<bar>') == r'"\u003cbar\u003e"'586587 def my_dumps(value, **options):588 assert options == {'foo': 'bar'}589 return '42'
3 unmodified lines
modified:CHANGES+10 added
1Jinja2 Changelog2================34Version 2.9.75-------------67(bugfix release, in development)89- ``tojson`` filter marks output as safe to match documented behavior.10 (`#718`_)1112.. _#718: https://github.com/pallets/jinja/pull/7181314Version 2.9.615-------------16(bugfix release, released on April 3rd 2017)17
503 unmodified lines