Skip to content
Myr

Fixed a bug in the subscript operation.

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

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent a5d8f55 · Browse files · 3 files+14 added−5 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+14 added−5 removed

  • tests:+8 added−0 removed
  • other:+6 added−5 removed

3 files+14 added−5 removed

modified:jinja2/compiler.py+2 added-5 removed
1297 unmodified lines
1298 self.visit(node.node, frame)1299 self.write(', %r)' % node.attr)13001301 def visit_Getitem(self, node, frame):1302 # slices or integer subscriptions bypass the getitem1303 # method if we can determine that at compile time.1304 if isinstance(node.arg, nodes.Slice) or \1305 (isinstance(node.arg, nodes.Const) and1306 isinstance(node.arg.value, (int, long))):1302 # slices bypass the environment getitem method.1303 if isinstance(node.arg, nodes.Slice):1304 self.visit(node.node, frame)1305 self.write('[')1306 self.visit(node.arg, frame)1307 self.write(']')
112 unmodified lines
modified:tests/test_undefined.py+8 added
4 unmodified lines
56 :copyright: 2008 by Armin Ronacher.7 :license: BSD, see LICENSE for more details.8"""9from py.test import raises10from jinja2 import Template11from jinja2.exceptions import UndefinedError121314test_default_undefined = '''15>>> from jinja2 import Environment, Undefined
58 unmodified lines
74Traceback (most recent call last):75 ...76UndefinedError: 'missing' is undefined77'''787980def test_indexing_gives_undefined():81 t = Template("{{ var[42].foo }}")82 raises(UndefinedError, t.render, var=0)
modified:CHANGES+4 added
12 unmodified lines
13 block to look up the wrong variable.1415- fixed a limitation in the lexer that made ``{{ foo.0.0 }}`` impossible.1617- index based subscribing of variables with a constant value returns an18 undefined object now instead of raising an index error. This was a bug19 caused by eager optimizing.2021Version 2.022-----------23(codename jinjavitus, released on July 17th 2008)24
32 unmodified lines