summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2016-12-19 13:44:02 -0500
committerTim Graham <timograham@gmail.com>2016-12-19 16:18:06 -0500
commit1a04b1762b50ea4d09eb1dc192d57172750b80aa (patch)
tree43e17ae389d6646d4476c6c0508dae545d517f44
parente233f357bd463df519ca5cd01106f1f59fb5733d (diff)
Refs #25484 -- Made non-staticfiles {% static %} tag quote its output.
-rw-r--r--django/templatetags/static.py4
-rw-r--r--tests/template_tests/syntax_tests/test_static.py12
2 files changed, 5 insertions, 11 deletions
diff --git a/django/templatetags/static.py b/django/templatetags/static.py
index 0f46fa33da..e4789bda71 100644
--- a/django/templatetags/static.py
+++ b/django/templatetags/static.py
@@ -2,7 +2,7 @@ from django import template
from django.apps import apps
from django.utils.encoding import iri_to_uri
from django.utils.html import conditional_escape
-from django.utils.six.moves.urllib.parse import urljoin
+from django.utils.six.moves.urllib.parse import quote, urljoin
register = template.Library()
@@ -116,7 +116,7 @@ class StaticNode(template.Node):
from django.contrib.staticfiles.storage import staticfiles_storage
return staticfiles_storage.url(path)
else:
- return urljoin(PrefixNode.handle_simple("STATIC_URL"), path)
+ return urljoin(PrefixNode.handle_simple("STATIC_URL"), quote(path))
@classmethod
def handle_token(cls, parser, token):
diff --git a/tests/template_tests/syntax_tests/test_static.py b/tests/template_tests/syntax_tests/test_static.py
index d5ca9ecf60..deb0ce6c78 100644
--- a/tests/template_tests/syntax_tests/test_static.py
+++ b/tests/template_tests/syntax_tests/test_static.py
@@ -51,13 +51,7 @@ class StaticTagTests(SimpleTestCase):
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):
+ @setup({'static-statictag05': '{% load static %}{% static "special?chars&quoted.html" %}'})
+ def test_static_quotes_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'))
+ self.assertEqual(output, urljoin(settings.STATIC_URL, '/static/special%3Fchars%26quoted.html'))