From: Armin Ronacher Date: Mon, 9 Jan 2017 15:50:54 +0000 (+0100) Subject: Resolved bad code generation on toplevel ifs X-Git-Tag: 2.9.4~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e73c574c2130ac71857b3beb5ebf03bf03de01d7;p=thirdparty%2Fjinja.git Resolved bad code generation on toplevel ifs This fixes #651 --- diff --git a/CHANGES b/CHANGES index 84a698a3..d2803654 100644 --- a/CHANGES +++ b/CHANGES @@ -9,6 +9,9 @@ Version 2.9.4 - Increment the bytecode cache version which was not done due to an oversight before. - Corrected bad code generation and scoping for filtered loops. (#649) +- Resolved an issue where top-level output silencing after known extend + blocks could generate invalid code when blocks where contained in if + statements. (#651) Version 2.9.3 ------------- diff --git a/jinja2/compiler.py b/jinja2/compiler.py index 2fde59a1..48f32109 100644 --- a/jinja2/compiler.py +++ b/jinja2/compiler.py @@ -367,8 +367,7 @@ class CodeGenerator(NodeVisitor): is no buffer a dummy ``if 0: yield None`` is written automatically. """ try: - if not nodes: - self.writeline('pass') + self.writeline('pass') for node in nodes: self.visit(node, frame) except CompilerExit: diff --git a/tests/test_regression.py b/tests/test_regression.py index 83e78afb..1d97cf76 100644 --- a/tests/test_regression.py +++ b/tests/test_regression.py @@ -479,3 +479,7 @@ class TestBug(object): '/bar', '', ] + + def test_empty_if(self, env): + t = env.from_string('{% if foo %}{% else %}42{% endif %}') + assert t.render(foo=False) == '42'