mirror of https://github.com/django/django.git
Fixed #34578 -- Made "join" template filter respect autoescape for joiner.
This commit is contained in:
parent
fce90950be
commit
a2da81fe08
|
@ -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)
|
||||
|
|
|
@ -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 = ["<p>Hello World!</p>", "beta & me", "<script>Hi!</script>"]
|
||||
context = {"var_list": var_list, "var_joiner": "<br/>"}
|
||||
output = self.engine.render_to_string("join_autoescape_off", context)
|
||||
expected_result = "<p>Hello World!</p><br/>beta & me<br/><script>Hi!</script>"
|
||||
self.assertEqual(output, expected_result)
|
||||
|
||||
|
||||
class FunctionTests(SimpleTestCase):
|
||||
def test_list(self):
|
||||
|
@ -69,7 +85,7 @@ class FunctionTests(SimpleTestCase):
|
|||
def test_autoescape_off(self):
|
||||
self.assertEqual(
|
||||
join(["<a>", "<img>", "</a>"], "<br>", autoescape=False),
|
||||
"<a><br><img><br></a>",
|
||||
"<a><br><img><br></a>",
|
||||
)
|
||||
|
||||
def test_noniterable_arg(self):
|
||||
|
|
Loading…
Reference in New Issue