summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Tracey <kmtracey@gmail.com>2009-12-12 17:29:46 +0000
committerKaren Tracey <kmtracey@gmail.com>2009-12-12 17:29:46 +0000
commit5e6c3d24b31af8af5514c6b7ecf700ae7836eef8 (patch)
treeb4ed00aa51df030cad045a2f5e1111bb51a30f9a
parent512ee70527e1b0c30a4db21d10f0129e00b7d991 (diff)
[1.1.X] Fixed #11972: Corrected title filter handling of numbers followed by letters. Thanks schwank@gmail.com and Randy Barlow.
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@11823 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--AUTHORS2
-rw-r--r--django/template/defaultfilters.py3
-rw-r--r--tests/regressiontests/templates/filters.py16
3 files changed, 15 insertions, 6 deletions
diff --git a/AUTHORS b/AUTHORS
index 06e1266155..7ea97b5537 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -54,6 +54,7 @@ answer newbie questions, and generally made Django that much better:
Niran Babalola <niran@niran.org>
Morten Bagai <m@bagai.com>
Mikaƫl Barbero <mikael.barbero nospam at nospam free.fr>
+ Randy Barlow <randy@electronsweatshop.com>
Scott Barr <scott@divisionbyzero.com.au>
Jiri Barton
Ned Batchelder <http://www.nedbatchelder.com/>
@@ -378,6 +379,7 @@ answer newbie questions, and generally made Django that much better:
Massimo Scamarcia <massimo.scamarcia@gmail.com>
David Schein
Bernd Schlapsi
+ schwank@gmail.com
scott@staplefish.com
Ilya Semenov <semenov@inetss.com>
serbaut@gmail.com
diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py
index 2957c3d045..a8c25670f6 100644
--- a/django/template/defaultfilters.py
+++ b/django/template/defaultfilters.py
@@ -249,7 +249,8 @@ stringformat.is_safe = True
def title(value):
"""Converts a string into titlecase."""
- return re.sub("([a-z])'([A-Z])", lambda m: m.group(0).lower(), value.title())
+ t = re.sub("([a-z])'([A-Z])", lambda m: m.group(0).lower(), value.title())
+ return re.sub("\d([A-Z])", lambda m: m.group(0).lower(), t)
title.is_safe = True
title = stringfilter(title)
diff --git a/tests/regressiontests/templates/filters.py b/tests/regressiontests/templates/filters.py
index 2b448574f7..88266e107b 100644
--- a/tests/regressiontests/templates/filters.py
+++ b/tests/regressiontests/templates/filters.py
@@ -120,13 +120,19 @@ def get_filter_tests():
# Notice that escaping is applied *after* any filters, so the string
# formatting here only needs to deal with pre-escaped characters.
- 'filter-stringformat01': ('{% autoescape off %}.{{ a|stringformat:"5s" }}. .{{ b|stringformat:"5s" }}.{% endautoescape %}', {"a": "a<b", "b": mark_safe("a<b")}, u". a<b. . a<b."),
- 'filter-stringformat02': ('.{{ a|stringformat:"5s" }}. .{{ b|stringformat:"5s" }}.', {"a": "a<b", "b": mark_safe("a<b")}, u". a&lt;b. . a<b."),
+ 'filter-stringformat01': ('{% autoescape off %}.{{ a|stringformat:"5s" }}. .{{ b|stringformat:"5s" }}.{% endautoescape %}',
+ {"a": "a<b", "b": mark_safe("a<b")}, u". a<b. . a<b."),
+ 'filter-stringformat02': ('.{{ a|stringformat:"5s" }}. .{{ b|stringformat:"5s" }}.', {"a": "a<b", "b": mark_safe("a<b")},
+ u". a&lt;b. . a<b."),
- # XXX No test for "title" filter; needs an actual object.
+ # Test the title filter
+ 'filter-title1' : ('{{ a|title }}', {'a' : 'JOE\'S CRAB SHACK'}, u'Joe&#39;s Crab Shack'),
+ 'filter-title2' : ('{{ a|title }}', {'a' : '555 WEST 53RD STREET'}, u'555 West 53rd Street'),
- 'filter-truncatewords01': ('{% autoescape off %}{{ a|truncatewords:"2" }} {{ b|truncatewords:"2"}}{% endautoescape %}', {"a": "alpha & bravo", "b": mark_safe("alpha &amp; bravo")}, u"alpha & ... alpha &amp; ..."),
- 'filter-truncatewords02': ('{{ a|truncatewords:"2" }} {{ b|truncatewords:"2"}}', {"a": "alpha & bravo", "b": mark_safe("alpha &amp; bravo")}, u"alpha &amp; ... alpha &amp; ..."),
+ 'filter-truncatewords01': ('{% autoescape off %}{{ a|truncatewords:"2" }} {{ b|truncatewords:"2"}}{% endautoescape %}',
+ {"a": "alpha & bravo", "b": mark_safe("alpha &amp; bravo")}, u"alpha & ... alpha &amp; ..."),
+ 'filter-truncatewords02': ('{{ a|truncatewords:"2" }} {{ b|truncatewords:"2"}}',
+ {"a": "alpha & bravo", "b": mark_safe("alpha &amp; bravo")}, u"alpha &amp; ... alpha &amp; ..."),
# The "upper" filter messes up entities (which are case-sensitive),
# so it's not safe for non-escaping purposes.