Skip to content

Commit bb3b012

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

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

examples/basic-examples.html

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,15 @@ <h3>6. Manual CSS Processing</h3>
297297
}
298298

299299
// Update custom properties status
300+
function escapeHtml(unsafe) {
301+
return unsafe
302+
.replace(/&/g, "&amp;")
303+
.replace(/</g, "&lt;")
304+
.replace(/>/g, "&gt;")
305+
.replace(/"/g, "&quot;")
306+
.replace(/'/g, "&#039;");
307+
}
308+
300309
function updateCustomPropsStatus() {
301310
const statusEl = document.getElementById("custom-props-status");
302311
const hasSupport = CSS.supports("--custom", "value");
@@ -331,8 +340,8 @@ <h3>6. Manual CSS Processing</h3>
331340
const outputCSS = CSSIfPolyfill.processCSSText(inputCSS);
332341

333342
outputEl.innerHTML = `
334-
<strong>Input:</strong> ${inputCSS}<br>
335-
<strong>Output:</strong> ${outputCSS}
343+
<strong>Input:</strong> ${escapeHtml(inputCSS)}<br>
344+
<strong>Output:</strong> ${escapeHtml(outputCSS)}
336345
`;
337346
};
338347

0 commit comments

Comments
 (0)