From 580c06f32d967b07839e4dc5199f959781201b68 Mon Sep 17 00:00:00 2001 From: Ajay Dhangar <99037494+ajay-dhangar@users.noreply.github.com> Date: Wed, 23 Sep 2026 09:21:25 +0530 Subject: [PATCH] Potential fix for code scanning alert no. 1824: DOM text reinterpreted as HTML Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- src/components/CodePlayground.jsx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/components/CodePlayground.jsx b/src/components/CodePlayground.jsx index 8c2939788..fe528e8ec 100644 --- a/src/components/CodePlayground.jsx +++ b/src/components/CodePlayground.jsx @@ -106,12 +106,13 @@ export default function CodePlayground({ language = 'javascript', initialCode = const executeCSS = () => { try { if (iframeRef.current) { - const htmlContent = ` + const iframeDoc = iframeRef.current.contentDocument || iframeRef.current.contentWindow.document; + iframeDoc.open(); + iframeDoc.write(` -
@@ -120,11 +121,13 @@ export default function CodePlayground({ language = 'javascript', initialCode =
- `; - const iframeDoc = iframeRef.current.contentDocument || iframeRef.current.contentWindow.document; - iframeDoc.open(); - iframeDoc.write(htmlContent); + `); iframeDoc.close(); + + const styleEl = iframeDoc.createElement('style'); + styleEl.textContent = code; + iframeDoc.head.appendChild(styleEl); + setOutput([{ type: 'info', message: 'CSS rendered successfully' }]); } } catch (err) {