Skip to content

Commit 00a1f77

Browse files
committed
fix: Replace HTML injection
1 parent 2c3c649 commit 00a1f77

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

filer/static/filer/js/base.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ document.addEventListener('DOMContentLoaded', () => {
156156
const actionsSelect = document.querySelector('.actions select[name="action"]');
157157
const actionsSelectOptions = actionsSelect?.querySelectorAll('option') || [];
158158
const actionsGo = document.querySelector('.actions button[type="submit"]');
159-
let html = '';
160159
const actionDelete = document.querySelector('.js-action-delete');
161160
const actionCopy = document.querySelector('.js-action-copy');
162161
const actionMove = document.querySelector('.js-action-move');
@@ -196,16 +195,23 @@ document.addEventListener('DOMContentLoaded', () => {
196195

197196
// mocking the action buttons to work in frontend UI
198197
actionsSelectOptions.forEach((option, index) => {
199-
let className = '';
200198
if (index !== 0) {
199+
const li = document.createElement('li');
200+
const a = document.createElement('a');
201+
a.href = '#';
202+
a.textContent = option.textContent;
203+
201204
if (option.value === valueDelete || option.value === valueCopy || option.value === valueMove) {
202-
className = 'class="hidden"';
205+
a.classList.add('hidden');
206+
}
207+
208+
li.appendChild(a);
209+
if (dropdown) {
210+
dropdown.appendChild(li);
203211
}
204-
html += `<li><a href="#"${className}>${option.textContent}</a></li>`;
205212
}
206213
});
207214
if (dropdown) {
208-
dropdown.insertAdjacentHTML('beforeend', html);
209215

210216
dropdown.addEventListener('click', (clickEvent) => {
211217
if (clickEvent.target.tagName === 'A') {

tests/frontend/unit/mocks.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,5 @@ window.django = {
99
jQuery: window.jQuery
1010
};
1111

12-
// Mediator is loaded from the bundle, so Cl.mediator should already exist
13-
// If not, we need to wait for the bundle to load
14-
if (!Cl.mediator) {
15-
console.warn('Cl.mediator not found - bundle may not be loaded yet');
16-
}
12+
// Mediator is loaded from the bundle, Cl.mediator is already initialized
13+

0 commit comments

Comments
 (0)