diff options
author | Moritz Sichert <moritz.sichert@googlemail.com> | 2015-03-10 21:21:28 +0100 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2015-03-18 09:11:01 -0400 |
commit | 6bff3439894ac22d80f270f36513fc86586273f3 (patch) | |
tree | e48e6b1e22cbf909e8cd41dc77c5e86f0e0c4ecd /tests/template_backends | |
parent | 465edf2bb2b6dd6158b198922dc0f185a15cc715 (diff) | |
download | django-6bff3439894ac22d80f270f36513fc86586273f3.tar.gz |
Refs #24469 -- Fixed escaping of forms, fields, and media in non-Django templates.
Diffstat (limited to 'tests/template_backends')
3 files changed, 28 insertions, 1 deletions
diff --git a/tests/template_backends/jinja2/template_backends/django_escaping.html b/tests/template_backends/jinja2/template_backends/django_escaping.html new file mode 100644 index 0000000000..a5ce51b109 --- /dev/null +++ b/tests/template_backends/jinja2/template_backends/django_escaping.html @@ -0,0 +1,5 @@ +{{ media }} + +{{ test_formĀ }} + +{{ test_form.test_field }} diff --git a/tests/template_backends/templates/template_backends/django_escaping.html b/tests/template_backends/templates/template_backends/django_escaping.html new file mode 100644 index 0000000000..a5ce51b109 --- /dev/null +++ b/tests/template_backends/templates/template_backends/django_escaping.html @@ -0,0 +1,5 @@ +{{ media }} + +{{ test_formĀ }} + +{{ test_form.test_field }} diff --git a/tests/template_backends/test_dummy.py b/tests/template_backends/test_dummy.py index 5f9a8dccb3..b529b70756 100644 --- a/tests/template_backends/test_dummy.py +++ b/tests/template_backends/test_dummy.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals +from django.forms import CharField, Form, Media from django.http import HttpRequest from django.middleware.csrf import CsrfViewMiddleware, get_token from django.template import TemplateDoesNotExist, TemplateSyntaxError @@ -43,7 +44,7 @@ class TemplateStringsTests(SimpleTestCase): # There's no way to trigger a syntax error with the dummy backend. # The test still lives here to factor it between other backends. if self.backend_name == 'dummy': - return + self.skipTest("test doesn't apply to dummy backend") with self.assertRaises(TemplateSyntaxError): self.engine.get_template('template_backends/syntax_error.html') @@ -55,6 +56,22 @@ class TemplateStringsTests(SimpleTestCase): self.assertIn('<script>', content) self.assertNotIn('<script>', content) + def test_django_html_escaping(self): + if self.backend_name == 'dummy': + self.skipTest("test doesn't apply to dummy backend") + + class TestForm(Form): + test_field = CharField() + + media = Media(js=['my-script.js']) + form = TestForm() + template = self.engine.get_template('template_backends/django_escaping.html') + content = template.render({'media': media, 'test_form': form}) + + expected = '{}\n\n{}\n\n{}'.format(media, form, form['test_field']) + + self.assertHTMLEqual(content, expected) + def test_csrf_token(self): request = HttpRequest() CsrfViewMiddleware().process_view(request, lambda r: None, (), {}) |