mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #33747 -- Added exception notes to the technical 500 debug page.
This commit is contained in:
committed by
Mariusz Felisiak
parent
70c945d6b3
commit
80c66e40f7
@@ -7,7 +7,7 @@ import tempfile
|
||||
import threading
|
||||
from io import StringIO
|
||||
from pathlib import Path
|
||||
from unittest import mock, skipIf
|
||||
from unittest import mock, skipIf, skipUnless
|
||||
|
||||
from django.core import mail
|
||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
@@ -22,6 +22,7 @@ from django.urls.converters import IntConverter
|
||||
from django.utils.functional import SimpleLazyObject
|
||||
from django.utils.regex_helper import _lazy_re_compile
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.version import PY311
|
||||
from django.views.debug import (
|
||||
CallableSettingWrapper,
|
||||
ExceptionCycleWarning,
|
||||
@@ -659,6 +660,40 @@ class ExceptionReporterTests(SimpleTestCase):
|
||||
text,
|
||||
)
|
||||
|
||||
@skipUnless(PY311, "Exception notes were added in Python 3.11.")
|
||||
def test_exception_with_notes(self):
|
||||
request = self.rf.get("/test_view/")
|
||||
try:
|
||||
try:
|
||||
raise RuntimeError("Oops")
|
||||
except Exception as err:
|
||||
err.add_note("First Note")
|
||||
err.add_note("Second Note")
|
||||
err.add_note(mark_safe("<script>alert(1);</script>"))
|
||||
raise err
|
||||
except Exception:
|
||||
exc_type, exc_value, tb = sys.exc_info()
|
||||
|
||||
reporter = ExceptionReporter(request, exc_type, exc_value, tb)
|
||||
html = reporter.get_traceback_html()
|
||||
self.assertIn(
|
||||
'<pre class="exception_value">Oops\nFirst Note\nSecond Note\n'
|
||||
"<script>alert(1);</script></pre>",
|
||||
html,
|
||||
)
|
||||
self.assertIn(
|
||||
"Exception Value: Oops\nFirst Note\nSecond Note\n"
|
||||
"<script>alert(1);</script>",
|
||||
html,
|
||||
)
|
||||
|
||||
text = reporter.get_traceback_text()
|
||||
self.assertIn(
|
||||
"Exception Value: Oops\nFirst Note\nSecond Note\n"
|
||||
"<script>alert(1);</script>",
|
||||
text,
|
||||
)
|
||||
|
||||
def test_mid_stack_exception_without_traceback(self):
|
||||
try:
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user