LibWeb/HTML: Ignore form owner if earlier same-ID element isn't a form

Only set form owner when there is no non-form element with the same ID
as the control's form attribute earlier in tree order.
This commit is contained in:
Glenn Skrzypczak 2025-11-23 21:01:57 +01:00 committed by Jelle Raaijmakers
parent 405e270583
commit a0dbae02c8
Notes: github-actions[bot] 2025-11-24 08:53:14 +00:00
3 changed files with 341 additions and 3 deletions

View file

@ -187,9 +187,10 @@ void FormAssociatedElement::reset_form_owner()
if (is_listed() && html_element.has_attribute(HTML::AttributeNames::form) && html_element.is_connected()) {
// 1. If the first element in element's tree, in tree order, to have an ID that is identical to element's form content attribute's value, is a form element, then associate the element with that form element.
auto form_value = html_element.attribute(HTML::AttributeNames::form);
html_element.root().for_each_in_inclusive_subtree_of_type<HTMLFormElement>([this, &form_value](HTMLFormElement& form_element) {
if (form_element.id() == form_value) {
set_form(&form_element);
html_element.root().for_each_in_inclusive_subtree_of_type<HTMLElement>([this, &form_value](auto& element) {
if (element.id() == form_value) {
if (is<HTMLFormElement>(element))
set_form(as<HTMLFormElement>(&element));
return TraversalDecision::Break;
}