]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
filter should accept objects. 236/head
authorJohn Boxall <john@mobify.me>
Wed, 29 May 2013 00:06:22 +0000 (17:06 -0700)
committerJohn Boxall <john@mobify.me>
Wed, 29 May 2013 00:06:22 +0000 (17:06 -0700)
jinja2/filters.py
jinja2/testsuite/filters.py

index 58c0bb66ae37bbb9c215679e8bf575afe21f59b9..8df262a01db6cb367073592df0ae0ad50036a2c4 100644 (file)
@@ -183,7 +183,7 @@ def do_title(s):
     uppercase letters, all remaining characters are lowercase.
     """
     rv = []
-    for item in re.compile(r'([-\s]+)(?u)').split(s):
+    for item in re.compile(r'([-\s]+)(?u)').split(soft_unicode(s)):
         if not item:
             continue
         rv.append(item[0].upper() + item[1:])
index 5219f767bf239b53f317479effa20d58c280368b..2aebb1333b50a4f83b44a031d3d38576465eb6b7 100644 (file)
@@ -205,6 +205,14 @@ class FilterTestCase(JinjaTestCase):
         tmpl = env.from_string('''{{ "foo\tbar"|title }}''')
         assert tmpl.render() == "Foo\tBar"
 
+        class Foo:
+            def __str__(self):
+                return 'foo-bar'
+
+        tmpl = env.from_string('''{{ data|title }}''')
+        out = tmpl.render(data=Foo())
+        assert out == 'Foo-Bar'
+
     def test_truncate(self):
         tmpl = env.from_string(
             '{{ data|truncate(15, true, ">>>") }}|'