]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
test for new identifier lexer
authorDavid Lord <davidism@gmail.com>
Sun, 2 Jul 2017 16:18:20 +0000 (09:18 -0700)
committerDavid Lord <davidism@gmail.com>
Sun, 2 Jul 2017 16:18:20 +0000 (09:18 -0700)
currently fails on special case unicode

jinja2/lexer.py
tests/test_lexnparse.py

index 3d48475a50b96528a8288f69ae43f1984edeb8e8..325b84718a5128011fff4284d7beae82e462483a 100644 (file)
@@ -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:
index 20d2c6d1e3e5d6c20586993afbcb45cd86c55510..be46eecc8bc468261dfdea097105e1e320314b01 100644 (file)
@@ -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