1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 23:38:12 +00:00

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
7 changed files with 62 additions and 10 deletions

View file

@ -530,9 +530,12 @@ WebIDL::ExceptionOr<void> Document::run_the_document_write_steps(StringView inpu
// 5. Insert input into the input stream just before the insertion point.
m_parser->tokenizer().insert_input_at_insertion_point(input);
// 6. If there is no pending parsing-blocking script, have the HTML parser process input, one code point at a time, processing resulting tokens as they are emitted, and stopping when the tokenizer reaches the insertion point or when the processing of the tokenizer is aborted by the tree construction stage (this can happen if a script end tag token is emitted by the tokenizer).
// 6. If there is no pending parsing-blocking script, have the HTML parser process input, one code point at a time,
// processing resulting tokens as they are emitted, and stopping when the tokenizer reaches the insertion point
// or when the processing of the tokenizer is aborted by the tree construction stage (this can happen if a script
// end tag token is emitted by the tokenizer).
if (!pending_parsing_blocking_script())
m_parser->run();
m_parser->run(HTML::HTMLTokenizer::StopAtInsertionPoint::Yes);
return {};
}