Skip to content

Commit 3cbcda5

Browse files
docs: Potential fix for code scanning alert no. 794: DOM text reinterpreted as HTML (#8172)
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent a81a861 commit 3cbcda5

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

docs/themes/v2/source/js/code-tabs.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ Test 1!
3131

3232

3333

34+
function escapeHTML(str) {
35+
return str.replace(/[&<>"']/g, function (char) {
36+
return {
37+
'&': '&amp;',
38+
'<': '&lt;',
39+
'>': '&gt;',
40+
'"': '&quot;',
41+
"'": '&#39;'
42+
}[char];
43+
});
44+
}
45+
3446
function openCodeTab(id, event) {
3547
const tabObj = document.querySelector(`${'#' + id}`);
3648
const anchorObj = document.querySelector(`${'#' + id + '-anchor'}`);
@@ -75,7 +87,7 @@ function openCodeTab(id, event) {
7587
'class="Heading XXSmall"' +
7688
'onclick="openCodeTab(\'' + id + '\', event)" ' +
7789
'href="#' + id + '-anchor">' +
78-
name +
90+
escapeHTML(name) +
7991
'</a>';
8092
})
8193

0 commit comments

Comments
 (0)