Skip to content

Commit

Permalink
Don't render an empty string when a tag's value is 0.
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Naeseth authored and defunkt committed Feb 9, 2010
1 parent abfba61 commit a708d12
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pystache/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ def render_tags(self, template, context):
@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):
Expand Down
5 changes: 5 additions & 0 deletions tests/test_pystache.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ def test_ignores_misses(self):
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)
Expand Down

0 comments on commit a708d12

Please sign in to comment.