Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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/trunk@11822 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit f761802b228826f31af48f520a2f4b70725801f6 1 parent 2659429
Karen Tracey authored December 12, 2009
2  AUTHORS
@@ -55,6 +55,7 @@ answer newbie questions, and generally made Django that much better:
55 55
     Niran Babalola <niran@niran.org>
56 56
     Morten Bagai <m@bagai.com>
57 57
     Mikaël Barbero <mikael.barbero nospam at nospam free.fr>
  58
+    Randy Barlow <randy@electronsweatshop.com>
58 59
     Scott Barr <scott@divisionbyzero.com.au>
59 60
     Jiri Barton
60 61
     Ned Batchelder <http://www.nedbatchelder.com/>
@@ -382,6 +383,7 @@ answer newbie questions, and generally made Django that much better:
382 383
     Massimo Scamarcia <massimo.scamarcia@gmail.com>
383 384
     David Schein
384 385
     Bernd Schlapsi
  386
+    schwank@gmail.com
385 387
     scott@staplefish.com
386 388
     Ilya Semenov <semenov@inetss.com>
387 389
     serbaut@gmail.com
3  django/template/defaultfilters.py
@@ -249,7 +249,8 @@ def stringformat(value, arg):
249 249
 
250 250
 def title(value):
251 251
     """Converts a string into titlecase."""
252  
-    return re.sub("([a-z])'([A-Z])", lambda m: m.group(0).lower(), value.title())
  252
+    t = re.sub("([a-z])'([A-Z])", lambda m: m.group(0).lower(), value.title())
  253
+    return re.sub("\d([A-Z])", lambda m: m.group(0).lower(), t)
253 254
 title.is_safe = True
254 255
 title = stringfilter(title)
255 256
 
20  tests/regressiontests/templates/filters.py
@@ -120,13 +120,19 @@ def get_filter_tests():
120 120
 
121 121
         # Notice that escaping is applied *after* any filters, so the string
122 122
         # formatting here only needs to deal with pre-escaped characters.
123  
-        'filter-stringformat01': ('{% autoescape off %}.{{ a|stringformat:"5s" }}. .{{ b|stringformat:"5s" }}.{% endautoescape %}', {"a": "a<b", "b": mark_safe("a<b")}, u".  a<b. .  a<b."),
124  
-        'filter-stringformat02': ('.{{ a|stringformat:"5s" }}. .{{ b|stringformat:"5s" }}.', {"a": "a<b", "b": mark_safe("a<b")}, u".  a&lt;b. .  a<b."),
125  
-
126  
-        # XXX No test for "title" filter; needs an actual object.
127  
-
128  
-        'filter-truncatewords01': ('{% autoescape off %}{{ a|truncatewords:"2" }} {{ b|truncatewords:"2"}}{% endautoescape %}', {"a": "alpha & bravo", "b": mark_safe("alpha &amp; bravo")}, u"alpha & ... alpha &amp; ..."),
129  
-        'filter-truncatewords02': ('{{ a|truncatewords:"2" }} {{ b|truncatewords:"2"}}', {"a": "alpha & bravo", "b": mark_safe("alpha &amp; bravo")}, u"alpha &amp; ... alpha &amp; ..."),
  123
+        'filter-stringformat01': ('{% autoescape off %}.{{ a|stringformat:"5s" }}. .{{ b|stringformat:"5s" }}.{% endautoescape %}',
  124
+            {"a": "a<b", "b": mark_safe("a<b")}, u".  a<b. .  a<b."),
  125
+        'filter-stringformat02': ('.{{ a|stringformat:"5s" }}. .{{ b|stringformat:"5s" }}.', {"a": "a<b", "b": mark_safe("a<b")},
  126
+            u".  a&lt;b. .  a<b."),
  127
+
  128
+        # Test the title filter
  129
+        'filter-title1' : ('{{ a|title }}', {'a' : 'JOE\'S CRAB SHACK'}, u'Joe&#39;s Crab Shack'),
  130
+        'filter-title2' : ('{{ a|title }}', {'a' : '555 WEST 53RD STREET'}, u'555 West 53rd Street'),
  131
+
  132
+        'filter-truncatewords01': ('{% autoescape off %}{{ a|truncatewords:"2" }} {{ b|truncatewords:"2"}}{% endautoescape %}',
  133
+            {"a": "alpha & bravo", "b": mark_safe("alpha &amp; bravo")}, u"alpha & ... alpha &amp; ..."),
  134
+        'filter-truncatewords02': ('{{ a|truncatewords:"2" }} {{ b|truncatewords:"2"}}',
  135
+            {"a": "alpha & bravo", "b": mark_safe("alpha &amp; bravo")}, u"alpha &amp; ... alpha &amp; ..."),
130 136
 
131 137
         # The "upper" filter messes up entities (which are case-sensitive),
132 138
         # so it's not safe for non-escaping purposes.

0 notes on commit f761802

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