srctree

Robin Linden parent 1145a986 62992f97
html: Require <style> to have an end tag

inlinesplit
html/parser.cpp added: 21, removed: 2, total 19
@@ -177,6 +177,11 @@ void Parser::operator()(html2::StartTagToken const &start_tag) {
open_elements_.pop();
}
 
// https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inhead
if (open_elements_.top()->name == "head" && start_tag.tag_name == "style") {
tokenizer_.set_state(html2::State::Rawtext);
}
 
auto &new_element = open_elements_.top()->children.emplace_back(
dom::Element{start_tag.tag_name, into_dom_attributes(start_tag.attributes), {}});
 
 
html/parser_test.cpp added: 21, removed: 2, total 19
@@ -285,5 +285,19 @@ int main() {
expect_eq(body_text, dom::Text{"hello?"});
});
 
etest::test("<style> consumes everything as raw text", [] {
auto html = html::parse("<style><body>"sv).html();
 
auto const &head = std::get<dom::Element>(html.children.at(0));
expect_eq(head.name, "head");
 
auto const &style = std::get<dom::Element>(head.children.at(0));
expect_eq(style.name, "style");
expect_eq(style.children.size(), std::size_t{1});
 
auto const &text = std::get<dom::Text>(style.children.at(0));
expect_eq(text.text, "<body>");
});
 
return etest::run_all_tests();
}