use std::fs;
use mini_docs::Builder;
#[test]
fn full_pipeline_strips_script_and_event_handler_before_safe_render() {
let input = tempfile::tempdir().expect("create input tempdir");
let templates = tempfile::tempdir().expect("create templates tempdir");
let output = tempfile::tempdir().expect("create output tempdir");
fs::write(
input.path().join("page.md"),
"# Title\n\n<script>alert(1)</script>\n\n<img src=\"x\" onerror=\"alert(1)\">\n",
)
.expect("write page.md");
fs::write(
templates.path().join("page.html"),
"<!doctype html><title>{{ page.title }}</title><body>{{ page.content | safe }}</body>",
)
.expect("write page.html");
Builder::new(input.path())
.templates(templates.path())
.output(output.path())
.default_template("page.html")
.build()
.expect("build should succeed");
let written = fs::read_to_string(output.path().join("page.html")).expect("read output file");
assert!(
!written.contains("<script>"),
"script tag survived sanitization: {written}"
);
assert!(
!written.contains("onerror"),
"event handler survived sanitization: {written}"
);
assert!(
written.contains("Title"),
"legitimate content was stripped too: {written}"
);
}