srctree

Robin Linden parent c9a3b0fd 6074b917
html2: Handle html elements in AfterHead

inlinesplit
html2/parser_states.cpp added: 19, removed: 6, total 13
@@ -396,10 +396,16 @@ std::optional<InsertionMode> InHeadNoscript::process(IActions &a, html2::Token c
}
 
std::optional<InsertionMode> AfterHead::process(IActions &a, html2::Token const &token) {
if (auto const *start = std::get_if<html2::StartTagToken>(&token); start && start->tag_name == "body") {
a.insert_element_for(*start);
a.set_frameset_ok(false);
return InBody{};
if (auto const *start = std::get_if<html2::StartTagToken>(&token); start != nullptr) {
if (start->tag_name == "html") {
return InBody{}.process(a, token);
}
 
if (start->tag_name == "body") {
a.insert_element_for(*start);
a.set_frameset_ok(false);
return InBody{};
}
}
 
return {};
 
html2/parser_states_test.cpp added: 19, removed: 6, total 13
@@ -275,6 +275,13 @@ void in_head_noscript_tests() {
}
 
void after_head_tests() {
etest::test("AfterHead: html", [] {
auto res = parse("<html foo=bar><head></head><html foo=baz hello=world>", {});
auto const &head = std::get<dom::Element>(res.document.html().children.at(0));
expect_eq(res.document.html().attributes, dom::AttrMap{{"foo", "bar"}, {"hello", "world"}});
expect_eq(head, dom::Element{"head"});
});
 
etest::test("AfterHead: body", [] {
auto res = parse("<body>", {});
expect_eq(res.document.html(), dom::Element{"html", {}, {dom::Element{"head"}, dom::Element{"body"}}});