Commit c7e71d8f by Chris Jerdonek

Fixed issue #118: "Handle lambda section values returning non-ascii, non-unicode"

See--

  https://github.com/defunkt/pystache/issues/118
parent ef3ef4bf
......@@ -8,6 +8,7 @@ History
``Renderer(missing_tags='strict')`` (issue #110).
* Bugfix: exceptions raised from a property are no longer swallowed when
getting a key from a context stack (issue #110).
* Bugfix: lambda section values can now return non-ascii, non-unicode strings (issue #118).
0.5.2 (2012-05-03)
------------------
......
......@@ -220,6 +220,8 @@ class RenderEngine(object):
#
# TODO: should we check the arity?
new_template = element(template[section_start_index:section_end_index])
# Make sure we are dealing with a unicode template string.
new_template = self.literal(new_template)
new_parsed_template = self._parse(new_template, delimiters=delims)
parts.append(new_parsed_template.render(context))
continue
......
......@@ -473,6 +473,23 @@ class RenderTests(unittest.TestCase, AssertStringMixin, AssertExceptionMixin):
context = {'test': (lambda text: 'Hi %s' % text)}
self._assert_render(u'Hi Mom', template, context)
def test_section__lambda__returning_nonascii_nonunicode(self):
"""
Test a lambda section value returning a non-ascii, non-unicode string.
"""
def literal(s):
if isinstance(s, unicode):
return s
return unicode(s, encoding='utf8')
engine = self._engine()
engine.literal = literal
template = '{{#lambda}}{{/lambda}}'
context = {'lambda': lambda text: u'abcdé'.encode('utf-8')}
self._assert_render(u'abcdé', template, context, engine=engine)
def test_section__iterable(self):
"""
Check that objects supporting iteration (aside from dicts) behave like lists.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment