浏览代码

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().
Andreas Kling 10 月之前
父节点
当前提交
a0ed12e839

+ 1 - 0
Tests/LibWeb/Text/expected/HTML/document-write-flush-character-insertions.txt

@@ -0,0 +1 @@
+PASS

+ 6 - 0
Tests/LibWeb/Text/input/HTML/document-write-flush-character-insertions.html

@@ -0,0 +1,6 @@
+<script src="../include.js"></script>
+<script>
+    test(() => {
+        document.write("PASS");
+    });
+</script>

+ 1 - 1
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())