summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMoritz Sichert <moritz.sichert@googlemail.com>2015-03-10 21:21:28 +0100
committerTim Graham <timograham@gmail.com>2015-03-18 09:11:44 -0400
commit571e093a258b00b25c24481af7acf0d0a034ec8c (patch)
treecc7a23f375ac4429086a7f0b5dec6456dd1a84c3 /tests
parent1cd2584c980ca547ba34d7b0f9d2dc89569803fb (diff)
[1.8.x] Refs #24469 -- Fixed escaping of forms, fields, and media in non-Django templates.
Backport of 6bff3439894ac22d80f270f36513fc86586273f3 from master
Diffstat (limited to 'tests')
-rw-r--r--tests/template_backends/jinja2/template_backends/django_escaping.html5
-rw-r--r--tests/template_backends/templates/template_backends/django_escaping.html5
-rw-r--r--tests/template_backends/test_dummy.py19
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('&lt;script&gt;', 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, (), {})