Skip to content

Commit ad55996

Browse files
committed
Fix #1662: Avoid assigning arbitrary attributes to SafeString instances
1 parent b539415 commit ad55996

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

debug_toolbar/panels/templates/views.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from django.template import Origin, TemplateDoesNotExist
44
from django.template.engine import Engine
55
from django.template.loader import render_to_string
6-
from django.utils.safestring import mark_safe
6+
from django.utils.html import format_html, mark_safe
77

88
from debug_toolbar.decorators import require_show_toolbar
99

@@ -50,12 +50,12 @@ def template_source(request):
5050
from pygments import highlight
5151
from pygments.formatters import HtmlFormatter
5252
from pygments.lexers import HtmlDjangoLexer
53-
53+
except ModuleNotFoundError:
54+
source = format_html("<code>{}</code>", source)
55+
pass
56+
else:
5457
source = highlight(source, HtmlDjangoLexer(), HtmlFormatter())
5558
source = mark_safe(source)
56-
source.pygmentized = True
57-
except ImportError:
58-
pass
5959

6060
content = render_to_string(
6161
"debug_toolbar/panels/template_source.html",

debug_toolbar/templates/debug_toolbar/panels/template_source.html

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ <h3>{% trans "Template source:" %} <code>{{ template_name }}</code></h3>
55
</div>
66
<div class="djDebugPanelContent">
77
<div class="djdt-scroll">
8-
{% if not source.pygmentized %}
9-
<code>{{ source }}</code>
10-
{% else %}
11-
{{ source }}
12-
{% endif %}
8+
{{ source }}
139
</div>
1410
</div>

0 commit comments

Comments
 (0)