Fixed #23060 -- Prevented UnicodeDecodeError in debug templatetag
This commit is contained in:
parent
90faa196f6
commit
08451f17d0
|
@ -87,7 +87,7 @@ class CycleNode(Node):
|
||||||
class DebugNode(Node):
|
class DebugNode(Node):
|
||||||
def render(self, context):
|
def render(self, context):
|
||||||
from pprint import pformat
|
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('\n\n')
|
||||||
output.append(pformat(sys.modules))
|
output.append(pformat(sys.modules))
|
||||||
return ''.join(output)
|
return ''.join(output)
|
||||||
|
|
|
@ -10,6 +10,7 @@ import warnings
|
||||||
|
|
||||||
from django import template
|
from django import template
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.contrib.auth.models import Group
|
||||||
from django.core import urlresolvers
|
from django.core import urlresolvers
|
||||||
from django.template import (base as template_base, loader, Context,
|
from django.template import (base as template_base, loader, Context,
|
||||||
RequestContext, Template, TemplateSyntaxError)
|
RequestContext, Template, TemplateSyntaxError)
|
||||||
|
@ -499,6 +500,15 @@ class TemplateRegressionTests(TestCase):
|
||||||
with self.assertRaises(urlresolvers.NoReverseMatch):
|
with self.assertRaises(urlresolvers.NoReverseMatch):
|
||||||
t.render(Context({}))
|
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.
|
# Set ALLOWED_INCLUDE_ROOTS so that ssi works.
|
||||||
@override_settings(MEDIA_URL="/media/", STATIC_URL="/static/",
|
@override_settings(MEDIA_URL="/media/", STATIC_URL="/static/",
|
||||||
|
|
Loading…
Reference in New Issue