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.)
This commit is contained in:
parent
bd857cd0fa
commit
54a6ae9201
Notes:
sideshowbarker
2024-07-19 11:07:25 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/54a6ae92011
1 changed files with 10 additions and 1 deletions
|
@ -118,7 +118,15 @@ static bool parse_html_document(const StringView& html, Document& document, Pare
|
||||||
};
|
};
|
||||||
|
|
||||||
auto commit_attribute = [&] {
|
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) {
|
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 == '>') {
|
if (ch == '>') {
|
||||||
|
commit_attribute();
|
||||||
commit_tag();
|
commit_tag();
|
||||||
move_to_state(State::Free);
|
move_to_state(State::Free);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Reference in a new issue