Bug 247593 - Fix form association behavior when a form and a control with form= are removed from a document together
Summary: Fix form association behavior when a form and a control with form= are remove...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Forms (show other bugs)
Version: Safari Technology Preview
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Ryosuke Niwa
URL:
Keywords: BrowserCompat, InRadar
Depends on:
Blocks:
 
Reported: 2022-11-07 15:39 PST by Ahmad Saleem
Modified: 2022-11-13 12:49 PST (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ahmad Saleem 2022-11-07 15:39:29 PST
Hi Team,

I came across another Blink Commit, where Safari Technology Preview 157 is failing one particular test case:

Commit - https://src.chromium.org/viewvc/blink?revision=197887&view=revision

Webkit Source - https://github.com/WebKit/WebKit/blob/7f186f0d780258408c1166c9432377365fa5d5b3/Source/WebCore/html/FormAssociatedElement.cpp#L94

Test Case - https://jsfiddle.net/f407psh1/show

Failing Test Case below:

- Check if a form and a control are disassociated when they are removed from the document together.
PASS owner.elements.length is 1
FAIL owner.elements.length should be 0. Was 1.

____

To do:

if (!insertionType.connectedToDocument && element.hasAttributeWithoutSynchronization(formAttr)) {
** Whatever is here already. ***
resetFormOwner();
return
}

We might need to add InsertionType to definition to "FormAssociatedElement.h" for "removedFromAncestor":

https://github.com/WebKit/WebKit/blob/7f186f0d780258408c1166c9432377365fa5d5b3/Source/WebCore/html/FormAssociatedElement.h#L97

___

Just wanted to create bug. Thanks!
Comment 1 Karl Dubost 2022-11-07 18:32:35 PST
The test case being

debug('- Check if a form and a control are disassociated when they are removed from the document together.');
container.innerHTML = '<div><input form=owner><form id=owner></form></div>';
owner = document.getElementById('owner');
shouldBe('owner.elements.length', '1');
container.firstChild.remove();
shouldBe('owner.elements.length', '0');



There is another sets of tests failing in this example.
https://jsfiddle.net/f407psh1/show
Probably worth a separate bug.


With  a form/option without a select element
  data:text/html,<form%20id=firstOwner><option%20id=firstOption></option></form>

and in the console:

  document.querySelector('#firstOption').form 

returns

  null in Firefox and Chrome
  The current HTMLFormElement() in Safari

Same for

  data:text/html,<form id=secondOwner><optgroup><option id=secondOption></option></optgroup></form>
Comment 2 Ahmad Saleem 2022-11-08 15:19:09 PST
I tried doing this change in following PR but failing because of HTMLObjectElement.cpp using same "removedFromAncestor" and when I modify it as well then I get following build error while also modifying "HTMLObjectElement.h":

error: non-virtual member function marked 'final' hides virtual member function

I am still learning C++ so I might not be able to solve it and is closing my PR for someone else to fix this:

https://github.com/WebKit/WebKit/pull/6229
Comment 3 Ryosuke Niwa 2022-11-12 19:59:43 PST
Pull request: https://github.com/WebKit/WebKit/pull/6437
Comment 4 EWS 2022-11-13 12:48:38 PST
Committed 256620@main (d16d7ec79683): <https://commits.webkit.org/256620@main>

Reviewed commits have been landed. Closing PR #6437 and removing active labels.
Comment 5 Radar WebKit Bug Importer 2022-11-13 12:49:19 PST
<rdar://problem/102295475>