From 054da77b6af4b9a07ac852aceac267b1d8daebf6 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Thu, 6 Nov 2025 07:10:48 -0800 Subject: [PATCH] Add test for unbalanced html in a header This is unexpectedly panicking. --- tests/testsuite/rendering.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/testsuite/rendering.rs b/tests/testsuite/rendering.rs index e0e77039..ea75fbd0 100644 --- a/tests/testsuite/rendering.rs +++ b/tests/testsuite/rendering.rs @@ -283,3 +283,25 @@ Check that the HTML tags are properly balanced. }) .check_main_file("book/chapter_1.html", str!["
xfoo
"]); } + +// 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") + .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![[""]]); +}