diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index 03676533b7..5289ef34a0 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -586,8 +586,9 @@ def join(value, arg, autoescape=True): """Join a list with a string, like Python's ``str.join(list)``.""" try: if autoescape: - value = [conditional_escape(v) for v in value] - data = conditional_escape(arg).join(value) + data = conditional_escape(arg).join([conditional_escape(v) for v in value]) + else: + data = arg.join(value) except TypeError: # Fail silently if arg isn't iterable. return value return mark_safe(data) diff --git a/tests/template_tests/filter_tests/test_join.py b/tests/template_tests/filter_tests/test_join.py index 08f68537ee..b92b732972 100644 --- a/tests/template_tests/filter_tests/test_join.py +++ b/tests/template_tests/filter_tests/test_join.py @@ -55,6 +55,22 @@ class JoinTests(SimpleTestCase): ) self.assertEqual(output, "alpha & beta & me") + @setup( + { + "join_autoescape_off": ( + "{% autoescape off %}" + "{{ var_list|join:var_joiner }}" + "{% endautoescape %}" + ), + } + ) + def test_join_autoescape_off(self): + var_list = ["
Hello World!
", "beta & me", ""] + context = {"var_list": var_list, "var_joiner": "Hello World!