diff options
author | Chris Wanstrath <chris@ozmm.org> | 2009-11-13 15:30:07 -0800 |
---|---|---|
committer | Chris Wanstrath <chris@ozmm.org> | 2009-11-13 15:30:07 -0800 |
commit | 90ae7cb48f650a7be6172adb875658caf91c1f1e (patch) | |
tree | a0e2c37cf323f3c567c291f8be2d6e5dbc5bfa21 | |
parent | 7fdebd3e5dcbf5e3f5f4d393f62415756514a059 (diff) | |
download | pystache-90ae7cb48f650a7be6172adb875658caf91c1f1e.tar.gz |
Ensure we're dealing with strings, always
-rw-r--r-- | HISTORY.md | 4 | ||||
-rw-r--r-- | pystache/template.py | 2 | ||||
-rw-r--r-- | tests/test_pystache.py | 9 |
3 files changed, 14 insertions, 1 deletions
@@ -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 = """ <ul> |