From c5d78bed5a05e5c34e5d16f7ea3c8c10dbe682c4 Mon Sep 17 00:00:00 2001 From: David Lord Date: Sun, 2 Jul 2017 09:18:20 -0700 Subject: [PATCH] test for new identifier lexer currently fails on special case unicode --- jinja2/lexer.py | 2 +- tests/test_lexnparse.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/jinja2/lexer.py b/jinja2/lexer.py index 3d48475a..325b8471 100644 --- a/jinja2/lexer.py +++ b/jinja2/lexer.py @@ -574,7 +574,7 @@ class Lexer(object): if check_ident and not value.isidentifier(): raise TemplateSyntaxError( 'Invalid character in identifier', - line, name, filename) + lineno, name, filename) elif token == 'string': # try to unescape string try: diff --git a/tests/test_lexnparse.py b/tests/test_lexnparse.py index 20d2c6d1..be46eecc 100644 --- a/tests/test_lexnparse.py +++ b/tests/test_lexnparse.py @@ -126,6 +126,27 @@ class TestLexer(object): result = tmpl.render() assert result == expect, (keep, template, result, expect) + @pytest.mark.parametrize('name,valid', ( + ('foo', True), + ('föö', True), + ('き', True), + ('_', True), + ('1a', False), + # special cases in addition to \w + ('\u1885', True), + ('\u1886', True), + ('\u2118', True), + ('\u212e', True), + )) + def test_name(self, env, name, valid): + t = '{{ ' + name + ' }}' + + if valid: + # shouldn't raise + env.from_string(t) + else: + pytest.raises(TemplateSyntaxError, env.from_string, t) + @pytest.mark.lexnparse @pytest.mark.parser -- 2.47.3