diff options
author | Andreas Kling <kling@serenityos.org> | 2020-03-25 18:50:10 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-03-25 18:50:10 +0100 |
commit | 90a53b3520cda8f19362ec6b7dc207f3bfb274f7 (patch) | |
tree | 4aeff0ce46151933d73e878c12f8d17030514393 /Libraries/LibWeb | |
parent | 5b8704322132d447eef42aded83ec3d1088ab9b1 (diff) | |
download | serenity-90a53b3520cda8f19362ec6b7dc207f3bfb274f7.zip |
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.
Diffstat (limited to 'Libraries/LibWeb')
-rw-r--r-- | Libraries/LibWeb/Parser/HTMLParser.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
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; } |