From 90a53b3520cda8f19362ec6b7dc207f3bfb274f7 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 25 Mar 2020 18:50:10 +0100 Subject: LibWeb: Commit uncommitted text at the end of HTML parse If there's any text left in the parse buffer at the end of HTML parsing we now commit it as a Text node. --- Libraries/LibWeb/Parser/HTMLParser.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'Libraries/LibWeb') diff --git a/Libraries/LibWeb/Parser/HTMLParser.cpp b/Libraries/LibWeb/Parser/HTMLParser.cpp index af945af006..7dfbfcdb10 100644 --- a/Libraries/LibWeb/Parser/HTMLParser.cpp +++ b/Libraries/LibWeb/Parser/HTMLParser.cpp @@ -95,6 +95,12 @@ static bool parse_html_document(const StringView& html, Document& document, Pare bool is_slash_tag = false; bool is_exclamation_tag = false; + auto commit_text_node = [&] { + auto text_node = adopt(*new Text(document, text_buffer.to_string())); + node_stack.last().append_child(text_node, false); + text_buffer.clear(); + }; + auto move_to_state = [&](State new_state) { if (new_state == State::BeforeTagName) { is_slash_tag = false; @@ -106,9 +112,8 @@ static bool parse_html_document(const StringView& html, Document& document, Pare attribute_name_buffer.clear(); if (new_state == State::BeforeAttributeValue) attribute_value_buffer.clear(); - if (state == State::Free && !text_buffer.string_view().is_empty()) { - auto text_node = adopt(*new Text(document, text_buffer.to_string())); - node_stack.last().append_child(text_node, false); + if (state == State::Free && !text_buffer.is_empty()) { + commit_text_node(); } state = new_state; text_buffer.clear(); @@ -348,6 +353,9 @@ static bool parse_html_document(const StringView& html, Document& document, Pare } } + if (!text_buffer.is_empty()) + commit_text_node(); + return true; } -- cgit v1.2.3