Permalink
Browse files

[1.7.x] Fixed #23060 -- Prevented UnicodeDecodeError in debug templat…

…etag

Backport of 08451f1 from master.
  • Loading branch information...
qingfeng authored and claudep committed Jul 21, 2014
1 parent 1ef544f commit 3a2badcbb73c2aed6451d2451da1c4fc8d934ab2
Showing with 11 additions and 1 deletion.
  1. +1 −1 django/template/defaulttags.py
  2. +10 −0 tests/template_tests/tests.py
@@ -89,7 +89,7 @@ def render(self, context):
class DebugNode(Node):
def render(self, context):
from pprint import pformat
- output = [pformat(val) for val in context]
+ output = [force_text(pformat(val)) for val in context]
output.append('\n\n')
output.append(pformat(sys.modules))
return ''.join(output)
@@ -10,6 +10,7 @@
from django import template
from django.conf import settings
+from django.contrib.auth.models import Group
from django.core import urlresolvers
from django.template import (base as template_base, loader, Context,
RequestContext, Template, TemplateSyntaxError)
@@ -524,6 +525,15 @@ def test_super_errors(self):
with self.assertRaises(urlresolvers.NoReverseMatch):
t.render(Context({}))
+ def test_debug_tag_non_ascii(self):
+ """
+ Test non-ASCII model representation in debug output (#23060).
+ """
+ Group.objects.create(name="清風")
+ c1 = Context({"objs": Group.objects.all()})
+ t1 = Template('{% debug %}')
+ self.assertIn("清風", t1.render(c1))
+
# Set ALLOWED_INCLUDE_ROOTS so that ssi works.
@override_settings(MEDIA_URL="/media/", STATIC_URL="/static/",

0 comments on commit 3a2badc

Please sign in to comment.