Skip to content

Commit 3061b04

Browse files
authored
🔀 Merge pull request #10 from LoupesDEV/alert-autofix-15
Potential fix for code scanning alert no. 15: DOM text reinterpreted as HTML
2 parents e9bc805 + aeff4d8 commit 3061b04

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

js/main.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,30 @@ function handleSearch(e) {
260260

261261
const titleEl = document.getElementById('titleText');
262262
if (titleEl) {
263-
titleEl.innerHTML = `Résultats pour "${q}" <span class="text-gray-500 text-sm ml-2">(${res.length})</span>`;
263+
titleEl.textContent = `Résultats pour "${q}" `;
264+
let countSpan = titleEl.querySelector('.text-gray-500.text-sm.ml-2');
265+
if (!countSpan) {
266+
countSpan = document.createElement('span');
267+
countSpan.className = 'text-gray-500 text-sm ml-2';
268+
titleEl.appendChild(countSpan);
269+
}
270+
countSpan.textContent = `(${res.length})`;
264271
} else {
265272
const sectionTitle = document.getElementById('sectionTitle');
266273
if (sectionTitle) {
267-
sectionTitle.innerHTML = `<span class="w-1 h-8 bg-red-600 rounded-full shadow-[0_0_15px_#dc2626]"></span>
268-
<span id="titleText" class="tracking-tight">Résultats pour "${q}" (${res.length})</span>`;
274+
while (sectionTitle.firstChild) {
275+
sectionTitle.removeChild(sectionTitle.firstChild);
276+
}
277+
278+
const accentSpan = document.createElement('span');
279+
accentSpan.className = 'w-1 h-8 bg-red-600 rounded-full shadow-[0_0_15px_#dc2626]';
280+
sectionTitle.appendChild(accentSpan);
281+
282+
const titleTextSpan = document.createElement('span');
283+
titleTextSpan.id = 'titleText';
284+
titleTextSpan.className = 'tracking-tight';
285+
titleTextSpan.textContent = `Résultats pour "${q}" (${res.length})`;
286+
sectionTitle.appendChild(titleTextSpan);
269287
}
270288
}
271289
renderGrid(res);

0 commit comments

Comments
 (0)