LibWeb: Use fallible FormAssociatedElement cast in form elements filter

The `HTMLFormControlsCollection` filter iterates all descendants of the
form's root, which may include non HTMLElement elements such as SVG
elements. The unchecked `as<FormAssociatedElement>` cast would crash on
these elements. Use `as_if` with a null check instead.

This fixes a regression introduced in 9af3e34875.
This commit is contained in:
Tim Ledbetter 2026-03-25 23:46:06 +00:00 committed by Shannon Booth
parent cdc264a62e
commit cbd01b8efc
Notes: github-actions[bot] 2026-03-26 07:31:55 +00:00
2 changed files with 11 additions and 3 deletions

View file

@ -519,11 +519,14 @@ static bool is_form_control(DOM::Element const& element, HTMLFormElement const&
return false;
}
auto const& form_associated_element = as<FormAssociatedElement>(element);
if (form_associated_element.form() != &form)
auto const* form_associated_element = as_if<FormAssociatedElement>(element);
if (!form_associated_element)
return false;
if (!form_associated_element.is_listed())
if (form_associated_element->form() != &form)
return false;
if (!form_associated_element->is_listed())
return false;
return true;