LibWeb: Parse <br/> into a self-closed br element

We were parsing "<br/>" as an open tag with the name "br/". This fixes
that specific scenario.

We also rename is_self_closing_tag() to is_void_element() to better fit
the specs.
This commit is contained in:
Andreas Kling 2020-04-18 20:33:28 +02:00
parent 6adea6069a
commit 88908be350
Notes: sideshowbarker 2024-07-19 07:30:11 +09:00

View file

@ -45,7 +45,7 @@ static bool is_valid_in_attribute_name(char ch)
return isalnum(ch) || ch == '_' || ch == '-';
}
static bool is_self_closing_tag(const StringView& tag_name)
static bool is_void_element(const StringView& tag_name)
{
return tag_name == "area"
|| tag_name == "base"
@ -133,7 +133,7 @@ static bool parse_html_document(const StringView& html, Document& document, Pare
node_stack[node_stack.size() - 2].append_child(new_element);
}
if (is_self_closing_tag(new_element->tag_name()))
if (is_void_element(new_element->tag_name()))
close_tag();
};
@ -258,6 +258,13 @@ static bool parse_html_document(const StringView& html, Document& document, Pare
move_to_state(State::InAttributeList);
break;
}
if (ch == '/' && peek(1) == '>') {
open_tag();
close_tag();
i += 1;
move_to_state(State::Free);
break;
}
if (ch == '>') {
commit_tag();
move_to_state(State::Free);