Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #7460 -- Made the "cache" template tag always generate keys tha…

…t can be

used with the memcache backend (which has the strongest restriction on keys).
Based on a patch from trbs.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@8533 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c46bb219bfd5cab84e20fc9e87238093d36ecf52 1 parent 29d2160
Malcolm Tredinnick authored August 25, 2008
3  django/templatetags/cache.py
@@ -2,6 +2,7 @@
2 2
 from django.template import resolve_variable
3 3
 from django.core.cache import cache
4 4
 from django.utils.encoding import force_unicode
  5
+from django.utils.http import urlquote
5 6
 
6 7
 register = Library()
7 8
 
@@ -22,7 +23,7 @@ def render(self, context):
22 23
         except (ValueError, TypeError):
23 24
             raise TemplateSyntaxError('"cache" tag got a non-integer timeout value: %r' % expire_time)
24 25
         # Build a unicode key for this fragment and all vary-on's.
25  
-        cache_key = u':'.join([self.fragment_name] + [force_unicode(resolve_variable(var, context)) for var in self.vary_on])
  26
+        cache_key = u':'.join([self.fragment_name] + [urlquote(resolve_variable(var, context)) for var in self.vary_on])
26 27
         value = cache.get(cache_key)
27 28
         if value is None:
28 29
             value = self.nodelist.render(context)
3  tests/regressiontests/templates/tests.py
@@ -917,6 +917,9 @@ def get_template_tests(self):
917 917
             'cache14': ('{% load cache %}{% cache foo bar %}{% endcache %}', {'foo': 'fail'}, template.TemplateSyntaxError),
918 918
             'cache15': ('{% load cache %}{% cache foo bar %}{% endcache %}', {'foo': []}, template.TemplateSyntaxError),
919 919
 
  920
+            # Regression test for #7460.
  921
+            'cache16': ('{% load cache %}{% cache 1 foo bar %}{% endcache %}', {'foo': 'foo', 'bar': 'with spaces'}, ''),
  922
+
920 923
             ### AUTOESCAPE TAG ##############################################
921 924
             'autoescape-tag01': ("{% autoescape off %}hello{% endautoescape %}", {}, "hello"),
922 925
             'autoescape-tag02': ("{% autoescape off %}{{ first }}{% endautoescape %}", {"first": "<b>hello</b>"}, "<b>hello</b>"),

0 notes on commit c46bb21

Please sign in to comment.
Something went wrong with that request. Please try again.