Skip to content

Commit

Permalink
Fix code scanning alert no. 70: DOM text reinterpreted as HTML
Browse files Browse the repository at this point in the history
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
  • Loading branch information
refaktor and github-advanced-security[bot] authored Jan 3, 2025
1 parent 5e8c4fe commit 4335308
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion info/tpl/menu.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
function escapeHtml(text) {
const map = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#039;'
};
return text.replace(/[&<>"']/g, function(m) { return map[m]; });
}

function generateMenuFromHeadings(node, hh) {
// Select all H2 elements
const h2Elements = node.querySelectorAll(hh);
Expand All @@ -14,7 +25,7 @@ function generateMenuFromHeadings(node, hh) {
// menuItem.textContent = h2.textContent;

// Optionally, set an id on the H2 for navigation
var index = h2.textContent;
var index = escapeHtml(h2.textContent);

const h2Id = `heading-${index}`;
h2.setAttribute('id', h2Id);
Expand Down

0 comments on commit 4335308

Please sign in to comment.