Skip to content

Truly independent web browser

LibWeb: Don't finish loading an XML document twice on parse errors

Andreas Kling869560bf3ba1
diff --git a/Libraries/LibWeb/DOM/DocumentLoading.cpp b/Libraries/LibWeb/DOM/DocumentLoading.cpp
index ec92f3315a5..0f866a41ff3 100644
--- a/Libraries/LibWeb/DOM/DocumentLoading.cpp
+++ b/Libraries/LibWeb/DOM/DocumentLoading.cpp
@@ -84,6 +84,12 @@ static void convert_to_xml_error_document(DOM::Document& document, Utf16String e
if (document.ready_for_post_load_tasks())
return;
+ // NB: The XML parser stops parsing at an error the way it does at the end of its input, so the end steps it started
+ // may still be running. They completely finish loading the document, and doing it here too would fire a second
+ // load event at the document's container.
+ if (document.has_html_parser_end_state())
+ return;
+
if (!document.is_completely_loaded())
document.completely_finish_loading();
diff --git a/Tests/LibWeb/Text/expected/XML/iframe-load-event-for-malformed-xml.txt b/Tests/LibWeb/Text/expected/XML/iframe-load-event-for-malformed-xml.txt
index 98e819ed274..df4fe8e2497 100644
--- a/Tests/LibWeb/Text/expected/XML/iframe-load-event-for-malformed-xml.txt
+++ b/Tests/LibWeb/Text/expected/XML/iframe-load-event-for-malformed-xml.txt
@@ -1 +1 @@
-iframe load event, document readyState: interactive
+iframe load event, document readyState: complete