Commit bd145e72 authored by Simon Charette's avatar Simon Charette
Browse files

Fixed #26536 -- Preserved leading dashes of the cached template loader keys.

Thanks Anders Roos for the report.
parent 218175b0
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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()
+3 −0
Original line number Diff line number Diff line
@@ -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`).
+7 −0
Original line number Diff line number Diff line
@@ -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):