From: Kevin Date: Mon, 11 May 2020 23:40:15 +0000 (-0400) Subject: Support the autoescape block X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fb82cba2c8dbe93fb096ccbab02db10c31d58fee;p=thirdparty%2Fjinja.git Support the autoescape block --- diff --git a/new_parser.py b/new_parser.py index 2a07f681..636eacbc 100644 --- a/new_parser.py +++ b/new_parser.py @@ -78,6 +78,9 @@ def parse_block(ast): def parse_block_pair(ast): block_name = ast['start']['name'] + if block_name == 'autoescape': + return parse_block_autoescape(ast) + if block_name == 'block': return parse_block_block(ast) @@ -98,6 +101,20 @@ def parse_block_pair(ast): return None +def parse_block_autoescape(ast): + return nodes.Scope( + [nodes.ScopedEvalContextModifier( + [nodes.Keyword( + 'autoescape', + parse_variable(ast['start']['parameters'][0]['value']), + lineno=lineno_from_parseinfo(ast['start']['parameters'][0]['parseinfo']) + )], + parse(ast['contents']), + lineno=lineno_from_parseinfo(ast['parseinfo']) + )], + lineno=lineno_from_parseinfo(ast['parseinfo']) + ) + def parse_block_block(ast): name = parse_variable(ast['start']['parameters'][0]['value']).name scoped = False diff --git a/test_template.jinja b/test_template.jinja index 3cefad88..fdd531af 100644 --- a/test_template.jinja +++ b/test_template.jinja @@ -49,4 +49,11 @@ across lines #} {%- endif %} {%- endfor %} - \ No newline at end of file + +{% autoescape true %} + Autoescaping is active within this block +{% endautoescape %} + +{% autoescape false %} + Autoescaping is inactive within this block +{% endautoescape %} \ No newline at end of file