Ticket #9483: patch_1_1.0.X.diff

File patch_1_1.0.X.diff, 2.2 KB (added by Henk de Vries, 16 years ago)

Patch against 1.0.X branch

  • django/template/defaultfilters.py

     
    210210
    211211def title(value):
    212212    """Converts a string into titlecase."""
    213     return re.sub("([a-z])'([A-Z])", lambda m: m.group(0).lower(), value.title())
     213    return re.sub("([a-z])'([A-Z])", lambda m: m.group(0).lower(), ' '.join([x.capitalize() for x in value.split()]))
    214214title.is_safe = True
    215215title = stringfilter(title)
    216216
  • tests/regressiontests/defaultfilters/tests.py

     
    100100>>> title(u'discoth\xe8que')
    101101u'Discoth\xe8que'
    102102
     103>>> title('fun&niest li"ne ever')
     104u'Fun&niest Li"ne Ever'
     105
    103106>>> truncatewords(u'A sentence with a few words in it', 1)
    104107u'A ...'
    105108
  • tests/regressiontests/templates/filters.py

     
    113113        'filter-stringformat01': ('{% autoescape off %}.{{ a|stringformat:"5s" }}. .{{ b|stringformat:"5s" }}.{% endautoescape %}', {"a": "a<b", "b": mark_safe("a<b")}, u".  a<b. .  a<b."),
    114114        'filter-stringformat02': ('.{{ a|stringformat:"5s" }}. .{{ b|stringformat:"5s" }}.', {"a": "a<b", "b": mark_safe("a<b")}, u".  a&lt;b. .  a<b."),
    115115
    116         # XXX No test for "title" filter; needs an actual object.
     116        # Check if "title" filter doesn't trip over quotes or ampersands
     117        'filter-title01': ('{{ a|title }}', {"a": "fun&niest li\"ne ever"}, "Fun&amp;niest Li&quot;ne Ever"),
    117118
    118119        'filter-truncatewords01': ('{% autoescape off %}{{ a|truncatewords:"2" }} {{ b|truncatewords:"2"}}{% endautoescape %}', {"a": "alpha & bravo", "b": mark_safe("alpha &amp; bravo")}, u"alpha & ... alpha &amp; ..."),
    119120        'filter-truncatewords02': ('{{ a|truncatewords:"2" }} {{ b|truncatewords:"2"}}', {"a": "alpha & bravo", "b": mark_safe("alpha &amp; bravo")}, u"alpha &amp; ... alpha &amp; ..."),
Back to Top