Skip to content

Commit 70738d0

Browse files
committed
Refs #2159 -- Do not HTML-escape traces in the cache panel
1 parent b40dd8a commit 70738d0

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

debug_toolbar/templates/debug_toolbar/panels/cache.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ <h4>{% translate "Calls" %}</h4>
6161
</tr>
6262
<tr class="djUnselected djToggleDetails_{{ forloop.counter }}" id="cacheDetails_{{ forloop.counter }}">
6363
<td colspan="1"></td>
64-
<td colspan="5"><pre class="djdt-stack">{{ call.trace }}</pre></td>
64+
<td colspan="5"><pre class="djdt-stack">{{ call.trace|safe }}</pre></td>
6565
</tr>
6666
{% endfor %}
6767
</tbody>

tests/panels/test_cache.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ def test_insert_content(self):
128128
content = self.panel.content
129129
self.assertIn("café", content)
130130
self.assertValidHTML(content)
131+
# ensure traces aren't escaped
132+
self.assertIn('<span class="djdt-path">', content)
131133

132134
def test_generate_server_timing(self):
133135
self.assertEqual(len(self.panel.calls), 0)

tests/test_store.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from django.test import TestCase
44
from django.test.utils import override_settings
5+
from django.utils.safestring import SafeData, mark_safe
56

67
from debug_toolbar import store
78

@@ -97,6 +98,18 @@ def test_panel(self):
9798
self.store.save_panel("bar", "bar.panel", {"a": 1})
9899
self.assertEqual(self.store.panel("bar", "bar.panel"), {"a": 1})
99100

101+
def test_serialize_safestring(self):
102+
before = {"string": mark_safe("safe")}
103+
104+
self.store.save_panel("bar", "bar.panel", before)
105+
after = self.store.panel("bar", "bar.panel")
106+
107+
self.assertFalse(type(before["string"]) is str)
108+
self.assertTrue(isinstance(before["string"], SafeData))
109+
110+
self.assertTrue(type(after["string"]) is str)
111+
self.assertFalse(isinstance(after["string"], SafeData))
112+
100113

101114
class StubStore(store.BaseStore):
102115
pass

0 commit comments

Comments
 (0)