diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-11-21 20:06:10 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-11-21 20:06:10 +0100 |
commit | 54a6ae920110eb4759812a08526703b45776f1a9 (patch) | |
tree | 69c3dc1b05a07744d15cf9d63fd08c69936e777f /Libraries/LibHTML | |
parent | bd857cd0fa57d7bbe05834c6ff50048e3137977c (diff) | |
download | serenity-54a6ae920110eb4759812a08526703b45776f1a9.zip |
LibHTML: Make the HTML parser handle <div attr> and <div attr="">
We were not producing the correct DOM attribute in either of those
cases. "<div attr>" would produce no attribute, and the other would
produce an attribute with null value (instead of an empty value.)
Diffstat (limited to 'Libraries/LibHTML')
-rw-r--r-- | Libraries/LibHTML/Parser/HTMLParser.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Libraries/LibHTML/Parser/HTMLParser.cpp b/Libraries/LibHTML/Parser/HTMLParser.cpp index b98bc7cb25..6ae4895169 100644 --- a/Libraries/LibHTML/Parser/HTMLParser.cpp +++ b/Libraries/LibHTML/Parser/HTMLParser.cpp @@ -118,7 +118,15 @@ static bool parse_html_document(const StringView& html, Document& document, Pare }; auto commit_attribute = [&] { - attributes.append({ String::copy(attribute_name_buffer), String::copy(attribute_value_buffer) }); + if (!attribute_name_buffer.is_empty()) { + auto name = String::copy(attribute_name_buffer); + String value; + if (attribute_value_buffer.is_empty()) + value = String::empty(); + else + value = String::copy(attribute_value_buffer); + attributes.empend(name, value); + } }; for (int i = 0; i < html.length(); ++i) { @@ -243,6 +251,7 @@ static bool parse_html_document(const StringView& html, Document& document, Pare } if (ch == '>') { + commit_attribute(); commit_tag(); move_to_state(State::Free); break; |