79634007

Date: 2025-05-22 14:55:40
Score: 3
Natty:
Report link
 let js_code: String = format!(r#"
        document.open();
        document.write(`{}`);
        document.close();
    "#,safe_html);   
    tab.evaluate(&js_code, true)?;  

具体细节:

    //转义html
    fn escape_js_template(html: &str) -> String {
        html.replace('\\', r"\\")  // 转义反斜杠
            .replace('`', r"\`")   // 转义反引号
            .replace('$', r"\$")  // 防止 `${}` 误解析
    }

    let html = r#"<doctype html>
    <html>
    <head><title>标题</title></head>
    <body>主体
    `ffffff`
    <a href="http://www.baidu.com">百度</a>
    </body>
    </html>"#;
    let safe_html = escape_js_template(html);
    let js_code: String = format!(r#"
    document.open();
    document.write(`{}`);
    document.close();
"#,safe_html);
   
    tab.evaluate(&js_code, true)?;  
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • No latin characters (3):
  • Low reputation (1):
Posted by: 唐子洋