]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
Fix for #304
authorArmin Ronacher <armin.ronacher@active-4.com>
Fri, 6 Jun 2014 15:48:42 +0000 (21:48 +0600)
committerArmin Ronacher <armin.ronacher@active-4.com>
Fri, 6 Jun 2014 15:49:37 +0000 (21:49 +0600)
jinja2/lexer.py

index 36042e0171df6a09b5ff337612fffd790c5681e0..d751cff083fc87236a280c4692eef9506476cb5a 100644 (file)
@@ -21,7 +21,7 @@ from collections import deque
 from jinja2.exceptions import TemplateSyntaxError
 from jinja2.utils import LRUCache
 from jinja2._compat import iteritems, implements_iterator, text_type, \
-     intern
+     intern, PY2
 
 
 # cache for the lexers. Exists in order to be able to have multiple
@@ -578,10 +578,11 @@ class Lexer(object):
                 # we do that for support of semi broken APIs
                 # as datetime.datetime.strftime.  On python 3 this
                 # call becomes a noop thanks to 2to3
-                try:
-                    value = str(value)
-                except UnicodeError:
-                    pass
+                if PY2:
+                    try:
+                        value = value.encode('ascii')
+                    except UnicodeError:
+                        pass
             elif token == 'integer':
                 value = int(value)
             elif token == 'float':