Skip to content
Browse files

Merge pull request #103 from njl/fix-issue-93

Fix to #93, this time respecting whitespace
  • Loading branch information...
2 parents e5763b3 + 8f0c8ee commit 796ee3ffac160b5747a010344765914a0dfba98a @rduplain rduplain committed
Showing with 16 additions and 1 deletion.
  1. +6 −1 jinja2/filters.py
  2. +10 −0 jinja2/testsuite/filters.py
View
7 jinja2/filters.py
@@ -176,7 +176,12 @@ def do_title(s):
"""Return a titlecased version of the value. I.e. words will start with
uppercase letters, all remaining characters are lowercase.
"""
- return soft_unicode(s).title()
+ rv = []
+ for item in re.compile(r'([-\s]+)(?u)').split(s):
+ if not item:
+ continue
+ rv.append(item[0].upper() + item[1:])
+ return ''.join(rv)
def do_dictsort(value, case_sensitive=False, by='key'):
View
10 jinja2/testsuite/filters.py
@@ -193,6 +193,16 @@ def test_string(self):
def test_title(self):
tmpl = env.from_string('''{{ "foo bar"|title }}''')
assert tmpl.render() == "Foo Bar"
+ tmpl = env.from_string('''{{ "foo's bar"|title }}''')
+ assert tmpl.render() == "Foo's Bar"
+ tmpl = env.from_string('''{{ "foo bar"|title }}''')
+ assert tmpl.render() == "Foo Bar"
+ tmpl = env.from_string('''{{ "f bar f"|title }}''')
+ assert tmpl.render() == "F Bar F"
+ tmpl = env.from_string('''{{ "foo-bar"|title }}''')
+ assert tmpl.render() == "Foo-Bar"
+ tmpl = env.from_string('''{{ "foo\tbar"|title }}''')
+ assert tmpl.render() == "Foo\tBar"
def test_truncate(self):
tmpl = env.from_string(

0 comments on commit 796ee3f

Please sign in to comment.
Something went wrong with that request. Please try again.