File tree Expand file tree Collapse file tree 6 files changed +25
-2
lines changed
debug_toolbar/templates/debug_toolbar/panels Expand file tree Collapse file tree 6 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -61,7 +61,7 @@ <h4>{% translate "Calls" %}</h4>
61
61
</ tr >
62
62
< tr class ="djUnselected djToggleDetails_{{ forloop.counter }} " id ="cacheDetails_{{ forloop.counter }} ">
63
63
< 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 >
65
65
</ tr >
66
66
{% endfor %}
67
67
</ tbody >
Original file line number Diff line number Diff line change 20
20
{% else %}
21
21
< span class ="djNoToggleSwitch "> </ span >
22
22
{% endif %}
23
- < span class ="djdt-stack "> {{ call.func_std_string }}</ span >
23
+ < span class ="djdt-stack "> {{ call.func_std_string|safe }}</ span >
24
24
</ div >
25
25
</ td >
26
26
< td > {{ call.cumtime|floatformat:3 }}</ td >
Original file line number Diff line number Diff line change @@ -112,6 +112,10 @@ def assertValidHTML(self, content):
112
112
msg_parts .append (f" { lines [position [0 ] - 1 ]} " )
113
113
raise self .failureException ("\n " .join (msg_parts ))
114
114
115
+ def reload_stats (self ):
116
+ data = self .toolbar .store .panel (self .toolbar .request_id , self .panel_id )
117
+ self .panel .load_stats_from_store (data )
118
+
115
119
116
120
class BaseTestCase (BaseMixin , TestCase ):
117
121
pass
Original file line number Diff line number Diff line change @@ -124,10 +124,13 @@ def test_insert_content(self):
124
124
# ensure the panel does not have content yet.
125
125
self .assertNotIn ("café" , self .panel .content )
126
126
self .panel .generate_stats (self .request , response )
127
+ self .reload_stats ()
127
128
# ensure the panel renders correctly.
128
129
content = self .panel .content
129
130
self .assertIn ("café" , content )
130
131
self .assertValidHTML (content )
132
+ # ensure traces aren't escaped
133
+ self .assertIn ('<span class="djdt-path">' , content )
131
134
132
135
def test_generate_server_timing (self ):
133
136
self .assertEqual (len (self .panel .calls ), 0 )
Original file line number Diff line number Diff line change @@ -35,11 +35,14 @@ def test_insert_content(self):
35
35
# ensure the panel does not have content yet.
36
36
self .assertNotIn ("regular_view" , self .panel .content )
37
37
self .panel .generate_stats (self .request , response )
38
+ self .reload_stats ()
38
39
# ensure the panel renders correctly.
39
40
content = self .panel .content
40
41
self .assertIn ("regular_view" , content )
41
42
self .assertIn ("render" , content )
42
43
self .assertValidHTML (content )
44
+ # ensure traces aren't escaped
45
+ self .assertIn ('<span class="djdt-path">' , content )
43
46
44
47
@override_settings (DEBUG_TOOLBAR_CONFIG = {"PROFILER_THRESHOLD_RATIO" : 1 })
45
48
def test_cum_time_threshold (self ):
Original file line number Diff line number Diff line change 2
2
3
3
from django .test import TestCase
4
4
from django .test .utils import override_settings
5
+ from django .utils .safestring import SafeData , mark_safe
5
6
6
7
from debug_toolbar import store
7
8
@@ -97,6 +98,18 @@ def test_panel(self):
97
98
self .store .save_panel ("bar" , "bar.panel" , {"a" : 1 })
98
99
self .assertEqual (self .store .panel ("bar" , "bar.panel" ), {"a" : 1 })
99
100
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
+
100
113
101
114
class StubStore (store .BaseStore ):
102
115
pass
You can’t perform that action at this time.
0 commit comments