summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authoralix- <alix-@users.noreply.github.com>2016-12-17 16:03:44 +0100
committerTim Graham <timograham@gmail.com>2016-12-17 10:03:44 -0500
commit374e6230ca9f9bb84cc9dd760dfb6395fbb5ff0f (patch)
tree2bb5d4cf963dbe31fd892225946300f1713bf5fa /tests
parent33e86b3488dbf29f5aeb38cf0ee6597190d33c59 (diff)
Fixed #25484 -- Made {% static %} render escaped URLs.
Diffstat (limited to 'tests')
-rw-r--r--tests/staticfiles_tests/cases.py2
-rw-r--r--tests/staticfiles_tests/test_templatetags.py2
-rw-r--r--tests/template_tests/syntax_tests/test_static.py11
3 files changed, 14 insertions, 1 deletions
diff --git a/tests/staticfiles_tests/cases.py b/tests/staticfiles_tests/cases.py
index abc4f1e81b..ea16101eb6 100644
--- a/tests/staticfiles_tests/cases.py
+++ b/tests/staticfiles_tests/cases.py
@@ -35,7 +35,7 @@ class BaseStaticFilesMixin(object):
def render_template(self, template, **kwargs):
if isinstance(template, six.string_types):
template = Template(template)
- return template.render(Context(kwargs)).strip()
+ return template.render(Context(**kwargs)).strip()
def static_template_snippet(self, path, asvar=False):
if asvar:
diff --git a/tests/staticfiles_tests/test_templatetags.py b/tests/staticfiles_tests/test_templatetags.py
index 7971ee1e51..050f19b179 100644
--- a/tests/staticfiles_tests/test_templatetags.py
+++ b/tests/staticfiles_tests/test_templatetags.py
@@ -8,3 +8,5 @@ class TestTemplateTag(StaticFilesTestCase):
def test_template_tag(self):
self.assertStaticRenders("does/not/exist.png", "/static/does/not/exist.png")
self.assertStaticRenders("testfile.txt", "/static/testfile.txt")
+ self.assertStaticRenders("test.html?foo=1&bar=2", "/static/test.html?foo=1&bar=2", autoescape=False)
+ self.assertStaticRenders("test.html?foo=1&bar=2", "/static/test.html?foo=1&amp;bar=2", autoescape=True)
diff --git a/tests/template_tests/syntax_tests/test_static.py b/tests/template_tests/syntax_tests/test_static.py
index 8ff90f5a5c..0cbe23a65a 100644
--- a/tests/template_tests/syntax_tests/test_static.py
+++ b/tests/template_tests/syntax_tests/test_static.py
@@ -50,3 +50,14 @@ class StaticTagTests(SimpleTestCase):
def test_static_statictag04(self):
output = self.engine.render_to_string('static-statictag04', {'base_css': 'admin/base.css'})
self.assertEqual(output, urljoin(settings.STATIC_URL, 'admin/base.css'))
+
+ @setup({'static-statictag05': '{% load static %}{% static "test.html?foo=1&bar=2" %}'})
+ def test_static_escapes_urls(self):
+ output = self.engine.render_to_string('static-statictag05')
+ self.assertEqual(output, urljoin(settings.STATIC_URL, '/static/test.html?foo=1&amp;bar=2'))
+
+ @setup({'static-statictag06': '{% load static %}'
+ '{% autoescape off %}{% static "test.html?foo=1&bar=2" %}{% endautoescape %}'})
+ def test_static_escapes_urls_autoescape_off(self):
+ output = self.engine.render_to_string('static-statictag06')
+ self.assertEqual(output, urljoin(settings.STATIC_URL, '/static/test.html?foo=1&bar=2'))