Skip to content
Myr

fixed awkward lexer bug in jinja that was yet untested

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 256c304 · Browse files · 4 files+23 added−16 removed
This commit

State

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

Diff stats

4 files+23 added−16 removed

  • tests:+6 added−0 removed
  • other:+17 added−16 removed

4 files+23 added−16 removed

modified:jinja/lexer.py+12 added-15 removed
274 unmodified lines
275276 # global lexing rules277 self.rules = {278 'root': [279 # raw directive280 (c('((?:\s*%s\-|%s)\s*raw\s*(?:\-%s\s*|%s%s))' % (281 e(environment.block_start_string),282 e(environment.block_start_string),283 e(environment.block_end_string),284 e(environment.block_end_string),285 block_suffix_re286 )), (None,), 'raw'),287 # normal directives288 (c('(.*?)(?:%s)' % '|'.join([289 '(?P<%s_begin>\s*%s\-|%s)' % (n, e(r), e(r))290 for n, r in root_tag_rules291 ])), ('data', '#bygroup'), '#bygroup'),279 # directives280 (c('(.*?)(?:%s)' % '|'.join(281 ['(?P<raw_begin>(?:\s*%s\-|%s)\s*raw\s*%s)' % (282 e(environment.block_start_string),283 e(environment.block_start_string),284 e(environment.block_end_string)285 )] + [286 '(?P<%s_begin>\s*%s\-|%s)' % (n, e(r), e(r))287 for n, r in root_tag_rules288 ])), ('data', '#bygroup'), '#bygroup'),289 # data290 (c('.+'), 'data', None)291 ],292 # comments
13 unmodified lines
306 block_suffix_re307 )), 'block_end', '#pop'),308 ] + tag_rules,309 # raw block313 'raw': [310 'raw_begin': [311 (c('(.*?)((?:\s*%s\-|%s)\s*endraw\s*(?:\-%s\s*|%s%s))' % (312 e(environment.block_start_string),313 e(environment.block_start_string),314 e(environment.block_end_string),315 e(environment.block_end_string),316 block_suffix_re320 )), ('data', None), '#pop'),317 )), ('data', 'raw_end'), '#pop'),318 (c('(.)'), (Failure('Missing end of raw directive'),), None)319 ]320 }321
192 unmodified lines
modified:jinja/parser.py+4 added
1078 unmodified lines
1079 if token_type == 'variable_begin':1080 next()1081 push_variable()1082 self.stream.expect('variable_end')1083 elif token_type == 'raw_begin':1084 next()1085 push_data()1086 self.stream.expect('raw_end')1087 elif token_type == 'block_begin':1088 next()1089 if test is not None and test(self.stream.current):1090 if drop_needle:
97 unmodified lines
modified:tests/test_lexer.py+6 added
5 unmodified lines
6 :copyright: 2007 by Armin Ronacher.7 :license: BSD, see LICENSE for more details.8"""910RAW = '{% raw %}foo{% endraw %}|{%raw%}{{ bar }}|{% baz %}{% endraw %}'11BALANCING = '''{% for item in seq %}${{'foo': item}|upper}{% endfor %}'''12COMMENTS = '''\13<ul>14<!--- for item in seq -->
2 unmodified lines
17</ul>'''18BYTEFALLBACK = u'''{{ 'foo'|pprint }}|{{ 'bär'|pprint }}'''192021def test_raw(env):22 tmpl = env.from_string(RAW)23 assert tmpl.render() == 'foo|{{ bar }}|{% baz %}'242526def test_balancing():27 from jinja import Environment28 env = Environment('{%', '%}', '${', '}')29 tmpl = env.from_string(BALANCING)
31 unmodified lines
modified:jdebug.py+1 added-1 removed
29 unmodified lines
30 x = e.loader.get_source(f)31 print PythonTranslator(e, Parser(e, x, f).parse(), None).translate()3233def l(x):34 for token in e.lexer.tokenize(x):34 for item in e.lexer.tokenize(x):35 print '%5s %-20s %r' % (item.lineno,36 item.type,37 item.value)38
32 unmodified lines