Commit a708d123 by Eric Naeseth Committed by Chris Wanstrath

Don't render an empty string when a tag's value is 0.

parent abfba610
......@@ -97,7 +97,10 @@ class Template(object):
@modifier(None)
def render_tag(self, tag_name, context):
"""Given a tag name and context, finds, escapes, and renders the tag."""
return cgi.escape(unicode(context.get(tag_name, '') or ''))
raw = context.get(tag_name, '')
if not raw and raw is not 0:
return ''
return cgi.escape(unicode(raw))
@modifier('!')
def render_comment(self, tag_name=None, context=None):
......
......@@ -27,6 +27,11 @@ class TestPystache(unittest.TestCase):
ret = pystache.render(template, { 'name': 'Jon' })
self.assertEquals(ret, "I think Jon wants a , right Jon?")
def test_render_zero(self):
template = 'My value is {{value}}.'
ret = pystache.render(template, { 'value': 0 })
self.assertEquals(ret, 'My value is 0.')
def test_comments(self):
template = "What {{! the }} what?"
ret = pystache.render(template)
......
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