Refs #25484 -- Removed incorrect unquoting in {% static %}.
Regression in 374e6230ca
.
Thanks Florian Apolloner for the report and analysis.
This commit is contained in:
parent
cc0bb07013
commit
e233f357bd
|
@ -2,7 +2,7 @@ from django import template
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.utils.encoding import iri_to_uri
|
from django.utils.encoding import iri_to_uri
|
||||||
from django.utils.html import conditional_escape
|
from django.utils.html import conditional_escape
|
||||||
from django.utils.six.moves.urllib.parse import unquote, urljoin
|
from django.utils.six.moves.urllib.parse import urljoin
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ class StaticNode(template.Node):
|
||||||
return self.handle_simple(path)
|
return self.handle_simple(path)
|
||||||
|
|
||||||
def render(self, context):
|
def render(self, context):
|
||||||
url = unquote(self.url(context))
|
url = self.url(context)
|
||||||
if context.autoescape:
|
if context.autoescape:
|
||||||
url = conditional_escape(url)
|
url = conditional_escape(url)
|
||||||
if self.varname is None:
|
if self.varname is None:
|
||||||
|
|
|
@ -58,6 +58,11 @@ class PathNotImplementedStorage(storage.Storage):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
|
class QueryStringStorage(storage.Storage):
|
||||||
|
def url(self, path):
|
||||||
|
return path + '?a=b&c=d'
|
||||||
|
|
||||||
|
|
||||||
class SimpleCachedStaticFilesStorage(CachedStaticFilesStorage):
|
class SimpleCachedStaticFilesStorage(CachedStaticFilesStorage):
|
||||||
|
|
||||||
def file_hash(self, name, content=None):
|
def file_hash(self, name, content=None):
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.test import override_settings
|
||||||
|
|
||||||
from .cases import StaticFilesTestCase
|
from .cases import StaticFilesTestCase
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,5 +10,14 @@ class TestTemplateTag(StaticFilesTestCase):
|
||||||
def test_template_tag(self):
|
def test_template_tag(self):
|
||||||
self.assertStaticRenders("does/not/exist.png", "/static/does/not/exist.png")
|
self.assertStaticRenders("does/not/exist.png", "/static/does/not/exist.png")
|
||||||
self.assertStaticRenders("testfile.txt", "/static/testfile.txt")
|
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("special?chars"ed.html", "/static/special%3Fchars%26quoted.html")
|
||||||
self.assertStaticRenders("test.html?foo=1&bar=2", "/static/test.html?foo=1&bar=2", autoescape=True)
|
|
||||||
|
@override_settings(STATICFILES_STORAGE='staticfiles_tests.storage.QueryStringStorage')
|
||||||
|
def test_template_tag_escapes(self):
|
||||||
|
"""
|
||||||
|
Storage.url() should return an encoded path and might be overridden
|
||||||
|
to also include a querystring. {% static %} escapes the URL to avoid
|
||||||
|
raw '&', for example.
|
||||||
|
"""
|
||||||
|
self.assertStaticRenders('a.html', 'a.html?a=b&c=d')
|
||||||
|
self.assertStaticRenders('a.html', 'a.html?a=b&c=d', autoescape=False)
|
||||||
|
|
Loading…
Reference in New Issue