summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2016-04-24 15:28:12 -0400
committerSimon Charette <charette.s@gmail.com>2016-04-24 22:17:36 -0400
commita06fa6e7d35b408264ee0c2e19d2040ef54c5b4d (patch)
tree53a38194f5d657c853f6aaf08a652f83c2777d75
parent7426c8fd82393404f1885606a646fda764b1e182 (diff)
downloaddjango-a06fa6e7d35b408264ee0c2e19d2040ef54c5b4d.tar.gz
[1.9.x] Fixed #26536 -- Preserved leading dashes of the cached template loader keys.
Thanks Anders Roos for the report. Backport of bd145e7209a0e628cced10384bd6f62d65c0f211 from master
-rw-r--r--django/template/loaders/cached.py2
-rw-r--r--docs/releases/1.9.6.txt3
-rw-r--r--tests/template_tests/test_loaders.py7
3 files changed, 11 insertions, 1 deletions
diff --git a/django/template/loaders/cached.py b/django/template/loaders/cached.py
index 70c55feb51..1a3851d280 100644
--- a/django/template/loaders/cached.py
+++ b/django/template/loaders/cached.py
@@ -100,7 +100,7 @@ class Loader(BaseLoader):
if template_dirs:
dirs_prefix = self.generate_hash(template_dirs)
- return ("%s-%s-%s" % (template_name, skip_prefix, dirs_prefix)).strip('-')
+ return '-'.join(filter(bool, [template_name, skip_prefix, dirs_prefix]))
def generate_hash(self, values):
return hashlib.sha1(force_bytes('|'.join(values))).hexdigest()
diff --git a/docs/releases/1.9.6.txt b/docs/releases/1.9.6.txt
index e505ee5923..1387aa9c4e 100644
--- a/docs/releases/1.9.6.txt
+++ b/docs/releases/1.9.6.txt
@@ -21,3 +21,6 @@ Bugfixes
* Fixed a regression where ``SessionBase.pop()`` returned ``None`` rather than
raising a ``KeyError`` for nonexistent values (:ticket:`26520`).
+
+* Fixed a regression causing the cached template loader to crash when using
+ template names starting with a dash (:ticket:`26536`).
diff --git a/tests/template_tests/test_loaders.py b/tests/template_tests/test_loaders.py
index 35921e0472..feafeb2b06 100644
--- a/tests/template_tests/test_loaders.py
+++ b/tests/template_tests/test_loaders.py
@@ -146,6 +146,13 @@ class CachedLoaderTests(SimpleTestCase):
# The two templates should not have the same content
self.assertNotEqual(t1.render(Context({})), t2.render(Context({})))
+ def test_template_name_leading_dash_caching(self):
+ """
+ #26536 -- A leading dash in a template name shouldn't be stripped
+ from its cache key.
+ """
+ self.assertEqual(self.engine.template_loaders[0].cache_key('-template.html', []), '-template.html')
+
@unittest.skipUnless(pkg_resources, 'setuptools is not installed')
class EggLoaderTests(SimpleTestCase):