Skip to content

Commit f1c03eb

Browse files
authored
Fix #1662: Avoid assigning arbitrary attributes to SafeString instances (#1663)
1 parent fa2774e commit f1c03eb

File tree

3 files changed

+6
-10
lines changed

3 files changed

+6
-10
lines changed

debug_toolbar/panels/templates/views.py

+4-5
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,11 @@ 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+
else:
5456
source = highlight(source, HtmlDjangoLexer(), HtmlFormatter())
5557
source = mark_safe(source)
56-
source.pygmentized = True
57-
except ImportError:
58-
pass
5958

6059
content = render_to_string(
6160
"debug_toolbar/panels/template_source.html",

debug_toolbar/templates/debug_toolbar/panels/template_source.html

+1-5
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>

tox.ini

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ deps =
1717
coverage
1818
Jinja2
1919
html5lib
20+
pygments
2021
selenium
2122
sqlparse
2223
passenv=

0 commit comments

Comments
 (0)