1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 04:08:11 +00:00

LibWeb: Check all <fieldset> ancestors in FormAssociatedElement::enabled

A form associated element is disabled if _any_ <fieldset> ancestor in
the ancestor chain has the disabled attribute, not just the first one.
This commit is contained in:
Luke Wilde 2022-09-30 16:19:01 +01:00 committed by Andreas Kling
parent 30815c25a2
commit c85fcd442f

View file

@ -37,11 +37,12 @@ bool FormAssociatedElement::enabled() const
return false;
// 2. The element is a descendant of a fieldset element whose disabled attribute is specified, and is not a descendant of that fieldset element's first legend element child, if any.
auto* fieldset_ancestor = html_element.first_ancestor_of_type<HTMLFieldSetElement>();
if (fieldset_ancestor && fieldset_ancestor->has_attribute(HTML::AttributeNames::disabled)) {
auto* first_legend_element_child = fieldset_ancestor->first_child_of_type<HTMLLegendElement>();
if (!first_legend_element_child || !html_element.is_descendant_of(*first_legend_element_child))
return false;
for (auto* fieldset_ancestor = html_element.first_ancestor_of_type<HTMLFieldSetElement>(); fieldset_ancestor; fieldset_ancestor = fieldset_ancestor->first_ancestor_of_type<HTMLFieldSetElement>()) {
if (fieldset_ancestor->has_attribute(HTML::AttributeNames::disabled)) {
auto* first_legend_element_child = fieldset_ancestor->first_child_of_type<HTMLLegendElement>();
if (!first_legend_element_child || !html_element.is_descendant_of(*first_legend_element_child))
return false;
}
}
return true;