Skip to content
Myr

Merge branch '0.10-maintenance'

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

authored by Armin Ronacher · committed by Armin Ronacher · parents 89731d8, c502dfb · Browse files · 3 files+28 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

3 files+28 added−2 removed

  • other:+28 added−2 removed

3 files+28 added−2 removed

modified:flask/testsuite/helpers.py+6 added
102 unmodified lines
103 rv = render('{{ "<!--<script>"|tojson }}')104 self.assert_equal(rv, '"\\u003c!--\\u003cscript\\u003e"')105 rv = render('{{ "&"|tojson }}')106 self.assert_equal(rv, '"\\u0026"')107 rv = render('{{ "\'"|tojson }}')108 self.assert_equal(rv, '"\\u0027"')109 rv = render("<a ng-data='{{ data|tojson }}'></a>",110 data={'x': ["foo", "bar", "baz'"]})111 self.assert_equal(rv,112 '<a ng-data=\'{"x": ["foo", "bar", "baz\\u0027"]}\'></a>')113114 def test_json_customization(self):115 class X(object):116 def __init__(self, val):
477 unmodified lines
modified:flask/json.py+17 added-2 removed
163 unmodified lines
164 this is available in templates through the ``|tojson`` filter which will165 also mark the result as safe. Due to how this function escapes certain166 characters this is safe even if used outside of ``<script>`` tags.167168 The following characters are escaped in strings:169170 - ``<``171 - ``>``172 - ``&``173 - ``'``174175 This makes it safe to embed such strings in any place in HTML with the176 notable exception of double quoted attributes. In that case single177 quote your attributes or HTML escape it in addition.178179 .. versionchanged:: 0.10180 This function's return value is now always safe for HTML usage, even170 if outside of script tags or if used in XHTML.181 if outside of script tags or if used in XHTML. This rule does not182 hold true when using this function in HTML attributes that are double183 quoted. Always single quote attributes if you use the ``|tojson``184 filter. Alternatively use ``|tojson|forceescape``.185 """186 rv = dumps(obj, **kwargs) \187 .replace(u'<', u'\\u003c') \188 .replace(u'>', u'\\u003e') \175 .replace(u'&', u'\\u0026')189 .replace(u'&', u'\\u0026') \190 .replace(u"'", u'\\u0027')191 if not _slash_escape:192 rv = rv.replace('\\/', '/')193 return rv194
49 unmodified lines
modified:CHANGES+5 added
6 unmodified lines
7--------------89Pending bugfix release.1011- Fixed an issue where ``|tojson`` was not quoting single quotes which12 made the filter not work properly in HTML attributes. Now it's13 possible to use that filter in single quoted attributes. This should14 make using that filter with angular.js easier.1516Version 0.1017------------1819Released on June 13nd 2013, codename Limoncello.
441 unmodified lines