]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Fixed #79
authorArmin Ronacher <armin.ronacher@active-4.com>
Sun, 19 May 2013 12:23:57 +0000 (13:23 +0100)
committerArmin Ronacher <armin.ronacher@active-4.com>
Sun, 19 May 2013 12:23:57 +0000 (13:23 +0100)
jinja2/compiler.py
jinja2/testsuite/inheritance.py

index 02df8c528e5c4f6e11c3cd3ebf2094781e70cb25..10c3fef02c260bd31238aa2dae70d1ff87d527b2 100644 (file)
@@ -892,12 +892,13 @@ class CodeGenerator(NodeVisitor):
                 self.indent()
             self.writeline('raise TemplateRuntimeError(%r)' %
                            'extended multiple times')
-            self.outdent()
 
             # if we have a known extends already we don't need that code here
             # as we know that the template execution will end here.
             if self.has_known_extends:
                 raise CompilerExit()
+            else:
+                self.outdent()
 
         self.writeline('parent_template = environment.get_template(', node)
         self.visit(node.template, frame)
index 7909b0314b7ee0b41c81611886bb0b5d3d770666..a5b946587fcc0752290356c81d34811ecfcd00a1 100644 (file)
@@ -12,7 +12,7 @@ import unittest
 
 from jinja2.testsuite import JinjaTestCase
 
-from jinja2 import Environment, DictLoader
+from jinja2 import Environment, DictLoader, TemplateError
 
 
 LAYOUTTEMPLATE = '''\
@@ -53,13 +53,27 @@ WORKINGTEMPLATE = '''\
 {% endblock %}
 '''
 
+DOUBLEEXTENDS = '''\
+{% extends "layout" %}
+{% extends "layout" %}
+{% block block1 %}
+  {% if false %}
+    {% block block2 %}
+      this should workd
+    {% endblock %}
+  {% endif %}
+{% endblock %}
+'''
+
+
 env = Environment(loader=DictLoader({
     'layout':       LAYOUTTEMPLATE,
     'level1':       LEVEL1TEMPLATE,
     'level2':       LEVEL2TEMPLATE,
     'level3':       LEVEL3TEMPLATE,
     'level4':       LEVEL4TEMPLATE,
-    'working':      WORKINGTEMPLATE
+    'working':      WORKINGTEMPLATE,
+    'doublee':      DOUBLEEXTENDS,
 }), trim_blocks=True)
 
 
@@ -219,6 +233,15 @@ class BugFixTestCase(JinjaTestCase):
         '''
         })).get_template("test.html").render().split() == [u'outer_box', u'my_macro']
 
+    def test_double_extends(self):
+        """Ensures that a template with more than 1 {% extends ... %} usage
+        raises a ``TemplateError``.
+        """
+        try:
+            tmpl = env.get_template('doublee')
+        except Exception, e:
+            assert isinstance(e, TemplateError)
+
 
 def suite():
     suite = unittest.TestSuite()