don't bypass autoescape
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parent 017c8d3 · Browse files · 2 files·+17 added−29 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+17 added−29 removed
- tests:+5 added−13 removed
- other:+12 added−16 removed
Provenance
- Commit
93565e6- Tree
943f52f- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
017c8d3
2 files changed+17 added−29 removed
modified:jinja2/ext.py+12 added-16 removed
441 unmodified lines442 pass443 444 445 class DebugExtension(Extension):446- """447- A ``{% debug %}`` tag that dumps the available variables, filters and tests.448- Typical usage like this:446+ """A ``{% debug %}`` tag that dumps the available variables,447+ filters, and tests.448 449 .. codeblock:: html+jinja450+451 <pre>{% debug %}</pre>452 453- produces output like this:453+ .. code-block:: python454 455- ::455 {'context': {'_': <function _gettext_alias at 0x7f9ceabde488>,456 'csrf_token': <SimpleLazyObject: 'lfPE7al...q3bykS4txKfb3'>,457 'cycler': <class 'jinja2.utils.Cycler'>,458 ...4 unmodified lines463 'tests': ['callable', 'checkbox_field', 'defined', 'divisibleby',464 'escaped', 'even', 'iterable', 'lower', 'mapping',465 'multiple_checkbox_field', ... 'string', 'undefined', 'upper']}466 467+ .. versionadded:: 2.11.0468 """469 tags = {'debug'}470 471 def __init__(self, environment):1 unmodified line473 474 def parse(self, parser):475 lineno = parser.stream.expect('name:debug').lineno476 context = ContextReference()477- call = self.call_method('_render', [context], lineno=lineno)478- return nodes.Output([nodes.MarkSafe(call)])477+ result = self.call_method('_render', [context], lineno=lineno)478+ return nodes.Output([result], lineno=lineno)479 480 def _render(self, context):481 result = {482 'filters': sorted(self.environment.filters.keys()),483 'tests': sorted(self.environment.tests.keys()),484 'context': context.get_all()485 }486- #487- # We set the depth since the intent is basically to show the top few488- # names. TODO: provide user control over this?489- #490- if version_info[:2] >= (3,4):491- text = pprint.pformat(result, depth=3, compact=True)486+487+ # Set the depth since the intent is to show the top few names.488+ if version_info[:2] >= (3, 4):489+ return pprint.pformat(result, depth=3, compact=True)490 else:493- text = pprint.pformat(result, depth=3)494- text = escape(text)495- return text491+ return pprint.pformat(result, depth=3)492 493 494 def extract_from_ast(node, gettext_functions=GETTEXT_FUNCTIONS,495 babel_style=True):190 unmodified linesmodified:tests/test_ext.py+5 added-13 removed
239 unmodified lines240 assert ext[0].__class__ is T1241 assert ext[1].__class__ is T2242 243 def test_debug(self):244- """Test for {% debug %}"""244 env = Environment(extensions=['jinja2.ext.debug'])246- tmpl = env.from_string('''Hello{% debug %}Bye''')247- out = tmpl.render()248- out = out.replace(''', "'").replace('<', '<').replace('>', '>')249- #250- # Check that some of the built-in items exist in the debug output...251- #252- assert "'context'" in out253- assert "'cycler'" in out254- assert "'filters'" in out255- assert "'abs'" in out256- assert "'tests'" in out257- assert "'!='" in out245+ t = env.from_string('Hello\n{% debug %}\nGoodbye')246+ out = t.render()247 248+ for value in ("context", "cycler", "filters", "abs", "tests", "!="):249+ assert "'{}'".format(value) in out250 251+252 @pytest.mark.ext253 class TestInternationalization(object):254 255 def test_trans(self):341 unmodified lines