File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
Windows Simulation/components/apps/browser Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,17 @@ interface BrowserAppProps {
88 initialFilePath ?: string
99}
1010
11+ // Utility to escape HTML special characters
12+ function escapeHtml ( str : string ) : string {
13+ return str
14+ . replace ( / & / g, "&" )
15+ . replace ( / < / g, "<" )
16+ . replace ( / > / g, ">" )
17+ . replace ( / " / g, """ )
18+ . replace ( / ' / g, "'" )
19+ . replace ( / \/ / g, "/" ) ;
20+ }
21+
1122export default function BrowserApp ( { initialFilePath } : BrowserAppProps ) {
1223 const [ filePath , setFilePath ] = useState ( initialFilePath || "C:\\My Documents\\index.html" )
1324 const [ htmlContent , setHtmlContent ] = useState ( "" )
@@ -31,11 +42,11 @@ export default function BrowserApp({ initialFilePath }: BrowserAppProps) {
3142 setHtmlContent ( content )
3243 api . info ( `Loaded HTML from ${ path } ` )
3344 } else {
34- setHtmlContent ( `<!-- Content of ${ path } -->\n<pre>${ content } </pre>` )
45+ setHtmlContent ( `<!-- Content of ${ escapeHtml ( path ) } -->\n<pre>${ escapeHtml ( content ) } </pre>` )
3546 api . warn ( "File is not an HTML file, displaying as plain text." )
3647 }
3748 } catch ( error : any ) {
38- setHtmlContent ( `<!-- Error loading ${ path } -->\n<pre>Error: ${ error . message } </pre>` )
49+ setHtmlContent ( `<!-- Error loading ${ escapeHtml ( path ) } -->\n<pre>Error: ${ escapeHtml ( error . message ) } </pre>` )
3950 api . error ( `Failed to load file: ${ error . message } ` )
4051 }
4152 }
You can’t perform that action at this time.
0 commit comments