mirror of https://github.com/django/django.git
[2.2.x] Fixed #30324 -- Forced utf-8 encoding when loading the template for the technical 500 debug page.
Regression in50b8493
. Related toea542a9
. Backport ofefb257a017
from master
This commit is contained in:
parent
54b65b83a2
commit
9da25fb832
|
@ -328,14 +328,14 @@ class ExceptionReporter:
|
|||
|
||||
def get_traceback_html(self):
|
||||
"""Return HTML version of debug 500 HTTP error page."""
|
||||
with Path(CURRENT_DIR, 'templates', 'technical_500.html').open() as fh:
|
||||
with Path(CURRENT_DIR, 'templates', 'technical_500.html').open(encoding='utf-8') as fh:
|
||||
t = DEBUG_ENGINE.from_string(fh.read())
|
||||
c = Context(self.get_traceback_data(), use_l10n=False)
|
||||
return t.render(c)
|
||||
|
||||
def get_traceback_text(self):
|
||||
"""Return plain text version of debug 500 HTTP error page."""
|
||||
with Path(CURRENT_DIR, 'templates', 'technical_500.txt').open() as fh:
|
||||
with Path(CURRENT_DIR, 'templates', 'technical_500.txt').open(encoding='utf-8') as fh:
|
||||
t = DEBUG_ENGINE.from_string(fh.read())
|
||||
c = Context(self.get_traceback_data(), autoescape=False, use_l10n=False)
|
||||
return t.render(c)
|
||||
|
|
|
@ -14,3 +14,6 @@ Bugfixes
|
|||
(:ticket:`30307`).
|
||||
|
||||
* Added compatibility for ``psycopg2`` 2.8 (:ticket:`30331`).
|
||||
|
||||
* Fixed a regression in Django 2.2 that caused a crash when loading the
|
||||
template for the technical 500 debug page (:ticket:`30324`).
|
||||
|
|
|
@ -6,6 +6,7 @@ import sys
|
|||
import tempfile
|
||||
from io import StringIO
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
from django.core import mail
|
||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
|
@ -20,7 +21,8 @@ from django.utils.safestring import mark_safe
|
|||
from django.utils.version import PY36
|
||||
from django.views.debug import (
|
||||
CLEANSED_SUBSTITUTE, CallableSettingWrapper, ExceptionReporter,
|
||||
cleanse_setting, technical_500_response,
|
||||
Path as DebugPath, cleanse_setting, default_urlconf,
|
||||
technical_404_response, technical_500_response,
|
||||
)
|
||||
|
||||
from ..views import (
|
||||
|
@ -610,6 +612,20 @@ class ExceptionReporterTests(SimpleTestCase):
|
|||
text = reporter.get_traceback_text()
|
||||
self.assertIn('USER: [unable to retrieve the current user]', text)
|
||||
|
||||
def test_template_encoding(self):
|
||||
"""
|
||||
The templates are loaded directly, not via a template loader, and
|
||||
should be opened as utf-8 charset as is the default specified on
|
||||
template engines.
|
||||
"""
|
||||
reporter = ExceptionReporter(None, None, None, None)
|
||||
with mock.patch.object(DebugPath, 'open') as m:
|
||||
reporter.get_traceback_html()
|
||||
m.assert_called_once_with(encoding='utf-8')
|
||||
m.reset_mock()
|
||||
reporter.get_traceback_text()
|
||||
m.assert_called_once_with(encoding='utf-8')
|
||||
|
||||
|
||||
class PlainTextReportTests(SimpleTestCase):
|
||||
rf = RequestFactory()
|
||||
|
|
Loading…
Reference in New Issue