Skip to content

Commit a0dbae0

Browse files
skyz1gmta
authored andcommitted
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.
1 parent 405e270 commit a0dbae0

File tree

3 files changed

+341
-3
lines changed

3 files changed

+341
-3
lines changed

Libraries/LibWeb/HTML/FormAssociatedElement.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,10 @@ void FormAssociatedElement::reset_form_owner()
187187
if (is_listed() && html_element.has_attribute(HTML::AttributeNames::form) && html_element.is_connected()) {
188188
// 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.
189189
auto form_value = html_element.attribute(HTML::AttributeNames::form);
190-
html_element.root().for_each_in_inclusive_subtree_of_type<HTMLFormElement>([this, &form_value](HTMLFormElement& form_element) {
191-
if (form_element.id() == form_value) {
192-
set_form(&form_element);
190+
html_element.root().for_each_in_inclusive_subtree_of_type<HTMLElement>([this, &form_value](auto& element) {
191+
if (element.id() == form_value) {
192+
if (is<HTMLFormElement>(element))
193+
set_form(as<HTMLFormElement>(&element));
193194
return TraversalDecision::Break;
194195
}
195196

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
Harness status: OK
2+
3+
Found 99 tests
4+
5+
99 Pass
6+
Pass Tests for parser inserted controls
7+
Pass [BUTTON] Basic form association - control with no form attribute is associated with ancestor
8+
Pass [BUTTON] Form owner is reset to null when control's form attribute is set to an ID that does not exist in the document
9+
Pass [BUTTON] Control whose form attribute is an empty string has no form owner
10+
Pass [BUTTON] Control whose form attribute is an empty string has no form owner even when form with empty attribute is present
11+
Pass [BUTTON] Control's form attribute must be a case sensitive match for the form's id
12+
Pass [BUTTON] Setting the form attribute of a control to the id of a non-ancestor form works
13+
Pass [BUTTON] Removing form id from a control resets the form owner to ancestor
14+
Pass [BUTTON] Removing the form owner of a control with form attribute resets the form owner to null
15+
Pass [BUTTON] Changing form attibute of control resets form owner to correct form
16+
Pass [BUTTON] Moving a control with form attribute within the document does not change the form owner
17+
Pass [BUTTON] When the id of a non-ancestor form changes from not being a match for the form attribute to being a match, the control's form owner is reset
18+
Pass [BUTTON] When form element with same ID as the control's form attribute is inserted earlier in tree order, the form owner is changed to the inserted form
19+
Pass [BUTTON] When non-form element with same ID as the control's form attribute is inserted earlier in tree order, the control does not have a form owner
20+
Pass [BUTTON] A control that is not in the document but has the form attribute set is associated with the nearest ancestor form if one exists
21+
Pass [FIELDSET] Basic form association - control with no form attribute is associated with ancestor
22+
Pass [FIELDSET] Form owner is reset to null when control's form attribute is set to an ID that does not exist in the document
23+
Pass [FIELDSET] Control whose form attribute is an empty string has no form owner
24+
Pass [FIELDSET] Control whose form attribute is an empty string has no form owner even when form with empty attribute is present
25+
Pass [FIELDSET] Control's form attribute must be a case sensitive match for the form's id
26+
Pass [FIELDSET] Setting the form attribute of a control to the id of a non-ancestor form works
27+
Pass [FIELDSET] Removing form id from a control resets the form owner to ancestor
28+
Pass [FIELDSET] Removing the form owner of a control with form attribute resets the form owner to null
29+
Pass [FIELDSET] Changing form attibute of control resets form owner to correct form
30+
Pass [FIELDSET] Moving a control with form attribute within the document does not change the form owner
31+
Pass [FIELDSET] When the id of a non-ancestor form changes from not being a match for the form attribute to being a match, the control's form owner is reset
32+
Pass [FIELDSET] When form element with same ID as the control's form attribute is inserted earlier in tree order, the form owner is changed to the inserted form
33+
Pass [FIELDSET] When non-form element with same ID as the control's form attribute is inserted earlier in tree order, the control does not have a form owner
34+
Pass [FIELDSET] A control that is not in the document but has the form attribute set is associated with the nearest ancestor form if one exists
35+
Pass [INPUT] Basic form association - control with no form attribute is associated with ancestor
36+
Pass [INPUT] Form owner is reset to null when control's form attribute is set to an ID that does not exist in the document
37+
Pass [INPUT] Control whose form attribute is an empty string has no form owner
38+
Pass [INPUT] Control whose form attribute is an empty string has no form owner even when form with empty attribute is present
39+
Pass [INPUT] Control's form attribute must be a case sensitive match for the form's id
40+
Pass [INPUT] Setting the form attribute of a control to the id of a non-ancestor form works
41+
Pass [INPUT] Removing form id from a control resets the form owner to ancestor
42+
Pass [INPUT] Removing the form owner of a control with form attribute resets the form owner to null
43+
Pass [INPUT] Changing form attibute of control resets form owner to correct form
44+
Pass [INPUT] Moving a control with form attribute within the document does not change the form owner
45+
Pass [INPUT] When the id of a non-ancestor form changes from not being a match for the form attribute to being a match, the control's form owner is reset
46+
Pass [INPUT] When form element with same ID as the control's form attribute is inserted earlier in tree order, the form owner is changed to the inserted form
47+
Pass [INPUT] When non-form element with same ID as the control's form attribute is inserted earlier in tree order, the control does not have a form owner
48+
Pass [INPUT] A control that is not in the document but has the form attribute set is associated with the nearest ancestor form if one exists
49+
Pass [OBJECT] Basic form association - control with no form attribute is associated with ancestor
50+
Pass [OBJECT] Form owner is reset to null when control's form attribute is set to an ID that does not exist in the document
51+
Pass [OBJECT] Control whose form attribute is an empty string has no form owner
52+
Pass [OBJECT] Control whose form attribute is an empty string has no form owner even when form with empty attribute is present
53+
Pass [OBJECT] Control's form attribute must be a case sensitive match for the form's id
54+
Pass [OBJECT] Setting the form attribute of a control to the id of a non-ancestor form works
55+
Pass [OBJECT] Removing form id from a control resets the form owner to ancestor
56+
Pass [OBJECT] Removing the form owner of a control with form attribute resets the form owner to null
57+
Pass [OBJECT] Changing form attibute of control resets form owner to correct form
58+
Pass [OBJECT] Moving a control with form attribute within the document does not change the form owner
59+
Pass [OBJECT] When the id of a non-ancestor form changes from not being a match for the form attribute to being a match, the control's form owner is reset
60+
Pass [OBJECT] When form element with same ID as the control's form attribute is inserted earlier in tree order, the form owner is changed to the inserted form
61+
Pass [OBJECT] When non-form element with same ID as the control's form attribute is inserted earlier in tree order, the control does not have a form owner
62+
Pass [OBJECT] A control that is not in the document but has the form attribute set is associated with the nearest ancestor form if one exists
63+
Pass [OUTPUT] Basic form association - control with no form attribute is associated with ancestor
64+
Pass [OUTPUT] Form owner is reset to null when control's form attribute is set to an ID that does not exist in the document
65+
Pass [OUTPUT] Control whose form attribute is an empty string has no form owner
66+
Pass [OUTPUT] Control whose form attribute is an empty string has no form owner even when form with empty attribute is present
67+
Pass [OUTPUT] Control's form attribute must be a case sensitive match for the form's id
68+
Pass [OUTPUT] Setting the form attribute of a control to the id of a non-ancestor form works
69+
Pass [OUTPUT] Removing form id from a control resets the form owner to ancestor
70+
Pass [OUTPUT] Removing the form owner of a control with form attribute resets the form owner to null
71+
Pass [OUTPUT] Changing form attibute of control resets form owner to correct form
72+
Pass [OUTPUT] Moving a control with form attribute within the document does not change the form owner
73+
Pass [OUTPUT] When the id of a non-ancestor form changes from not being a match for the form attribute to being a match, the control's form owner is reset
74+
Pass [OUTPUT] When form element with same ID as the control's form attribute is inserted earlier in tree order, the form owner is changed to the inserted form
75+
Pass [OUTPUT] When non-form element with same ID as the control's form attribute is inserted earlier in tree order, the control does not have a form owner
76+
Pass [OUTPUT] A control that is not in the document but has the form attribute set is associated with the nearest ancestor form if one exists
77+
Pass [SELECT] Basic form association - control with no form attribute is associated with ancestor
78+
Pass [SELECT] Form owner is reset to null when control's form attribute is set to an ID that does not exist in the document
79+
Pass [SELECT] Control whose form attribute is an empty string has no form owner
80+
Pass [SELECT] Control whose form attribute is an empty string has no form owner even when form with empty attribute is present
81+
Pass [SELECT] Control's form attribute must be a case sensitive match for the form's id
82+
Pass [SELECT] Setting the form attribute of a control to the id of a non-ancestor form works
83+
Pass [SELECT] Removing form id from a control resets the form owner to ancestor
84+
Pass [SELECT] Removing the form owner of a control with form attribute resets the form owner to null
85+
Pass [SELECT] Changing form attibute of control resets form owner to correct form
86+
Pass [SELECT] Moving a control with form attribute within the document does not change the form owner
87+
Pass [SELECT] When the id of a non-ancestor form changes from not being a match for the form attribute to being a match, the control's form owner is reset
88+
Pass [SELECT] When form element with same ID as the control's form attribute is inserted earlier in tree order, the form owner is changed to the inserted form
89+
Pass [SELECT] When non-form element with same ID as the control's form attribute is inserted earlier in tree order, the control does not have a form owner
90+
Pass [SELECT] A control that is not in the document but has the form attribute set is associated with the nearest ancestor form if one exists
91+
Pass [TEXTAREA] Basic form association - control with no form attribute is associated with ancestor
92+
Pass [TEXTAREA] Form owner is reset to null when control's form attribute is set to an ID that does not exist in the document
93+
Pass [TEXTAREA] Control whose form attribute is an empty string has no form owner
94+
Pass [TEXTAREA] Control whose form attribute is an empty string has no form owner even when form with empty attribute is present
95+
Pass [TEXTAREA] Control's form attribute must be a case sensitive match for the form's id
96+
Pass [TEXTAREA] Setting the form attribute of a control to the id of a non-ancestor form works
97+
Pass [TEXTAREA] Removing form id from a control resets the form owner to ancestor
98+
Pass [TEXTAREA] Removing the form owner of a control with form attribute resets the form owner to null
99+
Pass [TEXTAREA] Changing form attibute of control resets form owner to correct form
100+
Pass [TEXTAREA] Moving a control with form attribute within the document does not change the form owner
101+
Pass [TEXTAREA] When the id of a non-ancestor form changes from not being a match for the form attribute to being a match, the control's form owner is reset
102+
Pass [TEXTAREA] When form element with same ID as the control's form attribute is inserted earlier in tree order, the form owner is changed to the inserted form
103+
Pass [TEXTAREA] When non-form element with same ID as the control's form attribute is inserted earlier in tree order, the control does not have a form owner
104+
Pass [TEXTAREA] A control that is not in the document but has the form attribute set is associated with the nearest ancestor form if one exists

0 commit comments

Comments
 (0)