Kaydet (Commit) f7036b3e authored tarafından Mads Jensen's avatar Mads Jensen Kaydeden (comit) Tim Graham

Fixed #28662 -- Silenced join template filter error if arg isn't iterable.

üst d4fb7420
......@@ -518,11 +518,11 @@ def first(value):
@register.filter(is_safe=True, needs_autoescape=True)
def join(value, arg, autoescape=True):
"""Join a list with a string, like Python's ``str.join(list)``."""
if autoescape:
value = [conditional_escape(v) for v in value]
try:
if autoescape:
value = [conditional_escape(v) for v in value]
data = conditional_escape(arg).join(value)
except AttributeError: # fail silently but nicely
except TypeError: # Fail silently if arg isn't iterable.
return value
return mark_safe(data)
......
......@@ -65,3 +65,11 @@ class FunctionTests(SimpleTestCase):
join(['<a>', '<img>', '</a>'], '<br>', autoescape=False),
'<a>&lt;br&gt;<img>&lt;br&gt;</a>',
)
def test_noniterable_arg(self):
obj = object()
self.assertEqual(join(obj, '<br>'), obj)
def test_noniterable_arg_autoescape_off(self):
obj = object()
self.assertEqual(join(obj, '<br>', autoescape=False), obj)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment