Author: russellm Date: 2009-06-18 10:04:00 -0500 (Thu, 18 Jun 2009) New Revision: 11068
Modified: django/trunk/django/templatetags/cache.py django/trunk/tests/regressiontests/templates/tests.py Log: Fixed #11270 -- Modified cache template tag to prevent the creation of very long cache keys. Thanks to 235 for the report and patch. Modified: django/trunk/django/templatetags/cache.py =================================================================== --- django/trunk/django/templatetags/cache.py 2009-06-18 15:03:17 UTC (rev 11067) +++ django/trunk/django/templatetags/cache.py 2009-06-18 15:04:00 UTC (rev 11068) @@ -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 @@ 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) Modified: django/trunk/tests/regressiontests/templates/tests.py =================================================================== --- django/trunk/tests/regressiontests/templates/tests.py 2009-06-18 15:03:17 UTC (rev 11067) +++ django/trunk/tests/regressiontests/templates/tests.py 2009-06-18 15:04:00 UTC (rev 11068) @@ -1014,6 +1014,9 @@ # 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>"), --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-updates?hl=en -~----------~----~----~----~------~----~------~--~---