Ticket #6948: defaultfilters.patch

File defaultfilters.patch, 1.3 KB (added by dougvanhorn@…, 17 years ago)

Patch for join filter.

  • django/template/defaultfilters.py

     
    1111from django.conf import settings
    1212from django.utils.translation import ugettext, ungettext
    1313from django.utils.encoding import force_unicode, iri_to_uri
     14from django.utils.html import conditional_escape
    1415from django.utils.safestring import mark_safe, SafeData
    1516
    1617register = Library()
     
    442443        return u''
    443444first.is_safe = False
    444445
    445 def join(value, arg):
     446def join(value, arg, autoescape=None):
    446447    """Joins a list with a string, like Python's ``str.join(list)``."""
    447448    try:
    448         data = arg.join(map(force_unicode, value))
     449        esc = autoescape and conditional_escape or (lambda x: x)
     450        data = arg.join(map(esc, map(force_unicode, value)))
    449451    except AttributeError: # fail silently but nicely
    450452        return value
    451     safe_args = reduce(lambda lhs, rhs: lhs and isinstance(rhs, SafeData),
    452             value, True)
    453     if safe_args:
    454         return mark_safe(data)
    455     else:
    456         return data
     453    return mark_safe(data)
    457454join.is_safe = True
     455join.needs_autoescape = True
    458456
    459457def last(value):
    460458    "Returns the last item in a list"
Back to Top