LibWeb: Stop parsing after document.write at the insertion point

If a call to `document.write` inserts an incomplete HTML tag, e.g.:

    document.write("<p");

we would previously continue parsing the document until we reached a
closing angle bracket. However, the spec states we should stop once we
reach the new insertion point.
This commit is contained in:
Timothy Flynn 2024-02-18 12:45:53 -05:00 committed by Andreas Kling
parent 64dcd3f1f4
commit af57bd5cca
Notes: sideshowbarker 2024-07-16 23:05:02 +09:00
7 changed files with 62 additions and 10 deletions

View file

@ -169,14 +169,14 @@ void HTMLParser::visit_edges(Cell::Visitor& visitor)
m_list_of_active_formatting_elements.visit_edges(visitor);
}
void HTMLParser::run()
void HTMLParser::run(HTMLTokenizer::StopAtInsertionPoint stop_at_insertion_point)
{
for (;;) {
// FIXME: Find a better way to say that we come from Document::close() and want to process EOF.
if (!m_tokenizer.is_eof_inserted() && m_tokenizer.is_insertion_point_reached())
return;
auto optional_token = m_tokenizer.next_token();
auto optional_token = m_tokenizer.next_token(stop_at_insertion_point);
if (!optional_token.has_value())
break;
auto& token = optional_token.value();
@ -216,11 +216,11 @@ void HTMLParser::run()
flush_character_insertions();
}
void HTMLParser::run(const AK::URL& url)
void HTMLParser::run(const AK::URL& url, HTMLTokenizer::StopAtInsertionPoint stop_at_insertion_point)
{
m_document->set_url(url);
m_document->set_source(MUST(String::from_byte_string(m_tokenizer.source())));
run();
run(stop_at_insertion_point);
the_end(*m_document, this);
m_document->detach_parser({});
}