From 90ae7cb48f650a7be6172adb875658caf91c1f1e Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Fri, 13 Nov 2009 15:30:07 -0800 Subject: Ensure we're dealing with strings, always --- HISTORY.md | 4 ++++ pystache/template.py | 2 +- tests/test_pystache.py | 9 +++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index a6596d6..9b63c6f 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,7 @@ +## 0.1.1 (2009-11-12) + +* Ensure we're dealing with strings, always + ## 0.1.0 (2009-11-12) * First release diff --git a/pystache/template.py b/pystache/template.py index dd4ecee..10b72aa 100644 --- a/pystache/template.py +++ b/pystache/template.py @@ -94,7 +94,7 @@ 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(context.get(tag_name, '')) + return cgi.escape(str(context.get(tag_name, ''))) @modifier('!') def render_comment(self, tag_name=None, context=None): diff --git a/tests/test_pystache.py b/tests/test_pystache.py index 097021a..944df0f 100644 --- a/tests/test_pystache.py +++ b/tests/test_pystache.py @@ -35,6 +35,15 @@ class TestPystache(unittest.TestCase): ret = pystache.render(template, { 'set': True }) self.assertEquals(ret, "Ready set go!") + def test_non_strings(self): + template = "{{#stats}}({{key}} & {{value}}){{/stats}}" + stats = [] + stats.append({'key': 123, 'value': ['something']}) + stats.append({'key': u"chris", 'value': 0.900}) + + ret = pystache.render(template, { 'stats': stats }) + self.assertEquals(ret, """(123 & ['something'])(chris & 0.9)""") + def test_sections(self): template = """