From a0ed12e839f14b3ac80caca0e18a09ca256fd99d Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 21 Sep 2024 09:24:09 +0200 Subject: [PATCH] LibWeb: Always flush character insertions before exiting HTML parser This fixes an issue where document.write() with only text input would leave all the character data as unflushed text in the parser. This fixes many of the WPT tests for document.write(). --- .../HTML/document-write-flush-character-insertions.txt | 1 + .../HTML/document-write-flush-character-insertions.html | 6 ++++++ Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/expected/HTML/document-write-flush-character-insertions.txt create mode 100644 Tests/LibWeb/Text/input/HTML/document-write-flush-character-insertions.html diff --git a/Tests/LibWeb/Text/expected/HTML/document-write-flush-character-insertions.txt b/Tests/LibWeb/Text/expected/HTML/document-write-flush-character-insertions.txt new file mode 100644 index 00000000000..465701e3460 --- /dev/null +++ b/Tests/LibWeb/Text/expected/HTML/document-write-flush-character-insertions.txt @@ -0,0 +1 @@ +PASS \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/HTML/document-write-flush-character-insertions.html b/Tests/LibWeb/Text/input/HTML/document-write-flush-character-insertions.html new file mode 100644 index 00000000000..2098b00c670 --- /dev/null +++ b/Tests/LibWeb/Text/input/HTML/document-write-flush-character-insertions.html @@ -0,0 +1,6 @@ + + diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp index 2df5288cea7..f6b689237fa 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp @@ -177,7 +177,7 @@ 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; + break; auto optional_token = m_tokenizer.next_token(stop_at_insertion_point); if (!optional_token.has_value())