Add test for unbalanced html in a header

This is unexpectedly panicking.
This commit is contained in:
Eric Huss
2025-11-06 07:10:48 -08:00
parent bc7ca458b6
commit 054da77b6a

View File

@@ -283,3 +283,25 @@ Check that the HTML tags are properly balanced.
})
.check_main_file("book/chapter_1.html", str!["<div>x<span>foo</span></div>"]);
}
// Test for bug with unbalanced HTML handling in the heading.
#[test]
fn heading_with_unbalanced_html() {
BookTest::init(|_| {})
.change_file("src/chapter_1.md", "### Option<T>")
.run("build", |cmd| {
cmd.expect_failure().expect_stderr(str![[r#"
INFO Book building has started
INFO Running the html backend
thread 'main' ([..]) panicked at crates/mdbook-html/src/html/tree.rs:[..]
internal error: expected empty tag stack.
path: `chapter_1.md`
element=Element { name: QualName { prefix: None, ns: Atom('http://www.w3.org/1999/xhtml' type=static), local: Atom('h3' type=inline) }, attrs: {}, self_closing: false, was_raw: false }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
"#]]);
});
// .check_main_file("book/chapter_1.html", str![[""]]);
}