Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.0.X] Fixed #11270 -- Modified cache template tag to prevent the cr…

…eation of very long cache keys. Thanks to 235 for the report and patch.

Merge of r11068 from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@11070 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c9771f0b4a645c38fa7ef1996a24890c47e197d8 1 parent bb0538d
@freakboy3742 freakboy3742 authored
View
4 django/templatetags/cache.py
@@ -3,6 +3,7 @@
from django.core.cache import cache
from django.utils.encoding import force_unicode
from django.utils.http import urlquote
+from django.utils.hashcompat import md5_constructor
register = Library()
@@ -23,7 +24,8 @@ def render(self, context):
except (ValueError, TypeError):
raise TemplateSyntaxError('"cache" tag got a non-integer timeout value: %r' % expire_time)
# Build a unicode key for this fragment and all vary-on's.
- cache_key = u':'.join([self.fragment_name] + [urlquote(resolve_variable(var, context)) for var in self.vary_on])
+ args = md5_constructor(u':'.join([urlquote(resolve_variable(var, context)) for var in self.vary_on]))
+ cache_key = 'template.cache.%s.%s' % (self.fragment_name, args.hexdigest())
value = cache.get(cache_key)
if value is None:
value = self.nodelist.render(context)
View
3  tests/regressiontests/templates/tests.py
@@ -987,6 +987,9 @@ def get_template_tests(self):
# Regression test for #7460.
'cache16': ('{% load cache %}{% cache 1 foo bar %}{% endcache %}', {'foo': 'foo', 'bar': 'with spaces'}, ''),
+ # Regression test for #11270.
+ 'cache17': ('{% load cache %}{% cache 10 long_cache_key poem %}Some Content{% endcache %}', {'poem': 'Oh freddled gruntbuggly/Thy micturations are to me/As plurdled gabbleblotchits/On a lurgid bee/That mordiously hath bitled out/Its earted jurtles/Into a rancid festering/Or else I shall rend thee in the gobberwarts with my blurglecruncheon/See if I dont.'}, 'Some Content'),
+
### AUTOESCAPE TAG ##############################################
'autoescape-tag01': ("{% autoescape off %}hello{% endautoescape %}", {}, "hello"),
'autoescape-tag02': ("{% autoescape off %}{{ first }}{% endautoescape %}", {"first": "<b>hello</b>"}, "<b>hello</b>"),
Please sign in to comment.
Something went wrong with that request. Please try again.