From a708d123298e592468a55247de88303448a051d2 Mon Sep 17 00:00:00 2001 From: Eric Naeseth Date: Sun, 17 Jan 2010 07:04:01 +0800 Subject: Don't render an empty string when a tag's value is 0. --- pystache/template.py | 5 ++++- tests/test_pystache.py | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pystache/template.py b/pystache/template.py index 787304d..c942cd7 100644 --- a/pystache/template.py +++ b/pystache/template.py @@ -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): diff --git a/tests/test_pystache.py b/tests/test_pystache.py index 4298180..3f21a45 100644 --- a/tests/test_pystache.py +++ b/tests/test_pystache.py @@ -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) -- cgit v1.2.1