From f69001339f8da46dea4be614497020a36ada92b5 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 28 May 2020 00:23:34 +0200 Subject: [PATCH] LibWeb: Handle inline stylesheets a bit better in the new parser While we're still supporting both the old and the new parser, we have to deal with the way they load inline stylesheet (and scripts) a bit differently. The old parser loads all the text content up front, and then notifies the containing element. The new parser creates the containing element up front and appends text inside it afterwards. For now, we simply do an empty "children_changed" notification when first inserting a text node inside an element. This at least prevents the CSS parser from choking on a single-character stylesheet. --- Libraries/LibWeb/Parser/HTMLDocumentParser.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Libraries/LibWeb/Parser/HTMLDocumentParser.cpp b/Libraries/LibWeb/Parser/HTMLDocumentParser.cpp index b7968dd5c3..da342a4362 100644 --- a/Libraries/LibWeb/Parser/HTMLDocumentParser.cpp +++ b/Libraries/LibWeb/Parser/HTMLDocumentParser.cpp @@ -384,9 +384,11 @@ void HTMLDocumentParser::insert_character(u32 data) existing_text_node.set_data(builder.to_string()); return; } + auto new_text_node = adopt(*new Text(document(), "")); + adjusted_insertion_location->append_child(new_text_node); StringBuilder builder; builder.append(Utf32View { &data, 1 }); - adjusted_insertion_location->append_child(adopt(*new Text(document(), builder.to_string()))); + new_text_node->set_data(builder.to_string()); } void HTMLDocumentParser::handle_after_head(HTMLToken& token) @@ -827,6 +829,8 @@ void HTMLDocumentParser::handle_text(HTMLToken& token) return; } + // FIXME: This is a bit hackish, we can simplify this once we don't need to support + // the old parser anymore, since then we don't need to maintain its children_changed() semantics. if (token.is_end_tag() && token.tag_name() == "style") { current_node().children_changed(); // NOTE: We don't return here, keep going.