Skip to content

Commit 52cd3f0

Browse files
committed
Avoid rendering HTML data-store-id="None"
When panels are always rendered, the store_id is None. Previously, this was rendered into the HTML as data-store-id="None", which could appear to the JS as a valid store_id. Avoid rendering it entirely if the value is not needed.
1 parent 88ddc7b commit 52cd3f0

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

debug_toolbar/static/debug_toolbar/js/toolbar.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,15 @@
1919
} else {
2020
$('.djdt-panelContent').hide(); // Hide any that are already open
2121
var inner = current.find('.djDebugPanelContent .djdt-scroll'),
22-
store_id = $('#djDebug').data('store-id'),
23-
render_panel_url = $('#djDebug').data('render-panel-url');
24-
if (store_id !== '' && inner.children().length === 0) {
22+
store_id = $('#djDebug').data('store-id');
23+
if (store_id && inner.children().length === 0) {
2524
var ajax_data = {
2625
data: {
2726
store_id: store_id,
2827
panel_id: this.className
2928
},
3029
type: 'GET',
31-
url: render_panel_url
30+
url: $('#djDebug').data('render-panel-url')
3231
};
3332
$.ajax(ajax_data).done(function(data){
3433
inner.prev().remove(); // Remove AJAX loader

debug_toolbar/templates/debug_toolbar/base.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
{% endif %}
1212
<script src="{% static 'debug_toolbar/js/toolbar.js' %}"></script>
1313
<div id="djDebug" class="djdt-hidden" dir="ltr"
14-
data-store-id="{{ toolbar.store_id }}" data-render-panel-url="{% url 'djdt:render_panel' %}"
14+
{% if toolbar.store_id %}
15+
data-store-id="{{ toolbar.store_id }}"
16+
data-render-panel-url="{% url 'djdt:render_panel' %}"
17+
{% endif %}
1518
{{ toolbar.config.ROOT_TAG_EXTRA_ATTRS|safe }}>
1619
<div class="djdt-hidden" id="djDebugToolbar">
1720
<ul id="djDebugPanelList">

tests/test_integration.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,13 @@ def test_sql_profile_checks_show_toolbar(self):
219219
response = self.client.post(url, data, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
220220
self.assertEqual(response.status_code, 404)
221221

222+
@override_settings(DEBUG_TOOLBAR_CONFIG={'RENDER_PANELS': True})
223+
def test_data_store_id_not_rendered_when_none(self):
224+
url = '/regular/basic/'
225+
response = self.client.get(url)
226+
self.assertIn(b'id="djDebug"', response.content)
227+
self.assertNotIn(b'data-store-id', response.content)
228+
222229

223230
@unittest.skipIf(webdriver is None, "selenium isn't installed")
224231
@unittest.skipUnless('DJANGO_SELENIUM_TESTS' in os.environ, "selenium tests not requested")

0 commit comments

Comments
 (0)