From f761802b228826f31af48f520a2f4b70725801f6 Mon Sep 17 00:00:00 2001 From: Karen Tracey Date: Sat, 12 Dec 2009 17:20:32 +0000 Subject: [PATCH] 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 --- AUTHORS | 2 ++ django/template/defaultfilters.py | 3 ++- tests/regressiontests/templates/filters.py | 16 +++++++++++----- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/AUTHORS b/AUTHORS index 27fe91bcc5..eb13f99ca6 100644 --- a/AUTHORS +++ b/AUTHORS @@ -55,6 +55,7 @@ answer newbie questions, and generally made Django that much better: Niran Babalola Morten Bagai Mikaƫl Barbero + Randy Barlow Scott Barr Jiri Barton Ned Batchelder @@ -382,6 +383,7 @@ answer newbie questions, and generally made Django that much better: Massimo Scamarcia David Schein Bernd Schlapsi + schwank@gmail.com scott@staplefish.com Ilya Semenov 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