Bug 274214 - Constructed FormData object should not contain entries for the Image Button submitter by default
Summary: Constructed FormData object should not contain entries for the Image Button s...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Forms (show other bugs)
Version: Safari 16
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: BrowserCompat, InRadar
Depends on:
Blocks:
 
Reported: 2024-05-15 09:00 PDT by Jon Jensen
Modified: 2024-05-17 20:36 PDT (History)
7 users (show)

See Also:


Attachments
testcase (1.19 KB, text/html)
2024-05-15 21:12 PDT, Karl Dubost
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jon Jensen 2024-05-15 09:00:44 PDT
Overview:
When a `FormData` object is constructed in a submit handler, it automatically contains entries for the Image Button submitter even if the `submitter` parameter is not passed to the constructor. This does not happen with regular (non-image) submitters. This also does not happen in Chromium or Gecko.

This is related to https://bugs.webkit.org/show_bug.cgi?id=239070, but was not resolved by https://commits.webkit.org/r293444

Steps to Reproduce:

1. Create a page with the following content:
> <script>
>   function onSubmit(event) {
>     event.preventDefault();
>     const formData = new FormData(event.target);
>     console.log(new URLSearchParams(formData).toString());
>   }
> </script>
> <form onsubmit="onSubmit(event)">
>   <input
>     name="submitter"
>     type="image"
>     name="input"
>     href="/some/image.png"
>     alt="Image Button"
>   />
> </form>

```
2. Click the `Image Button`

Actual Results:
Something like `submitter.x=10&submitter.y=4` is logged

Expected Results:
An empty string should be logged. The submitter should only be included in the FormData object if it is explicitly passed to the constructor. See https://developer.mozilla.org/en-US/docs/Web/API/FormData/FormData#submitter
Comment 1 Karl Dubost 2024-05-15 21:12:40 PDT
Created attachment 471419 [details]
testcase

Adding the testcase
Comment 2 Radar WebKit Bug Importer 2024-05-15 22:13:02 PDT
<rdar://problem/128176811>
Comment 3 Ahmad Saleem 2024-05-16 05:44:40 PDT
This is even earlier attempt of bug 239070 which tried to extend WPT test as well for image.

https://bugs.webkit.org/show_bug.cgi?id=234069

Also later `image` changes from bug 234069 were not carried into 239070. So it might be just reapplying 234069 (image specific changes)?
Comment 4 Ahmad Saleem 2024-05-16 05:54:12 PDT
(In reply to Ahmad Saleem from comment #3)
> This is even earlier attempt of bug 239070 which tried to extend WPT test as
> well for image.
> 
> https://bugs.webkit.org/show_bug.cgi?id=234069
> 
> Also later `image` changes from bug 234069 were not carried into 239070. So
> it might be just reapplying 234069 (image specific changes)?

Confirmed on local build that just doing `image` specific changes from bug 234069 fixes this test case.
Comment 5 Ahmad Saleem 2024-05-16 06:08:02 PDT
Next steps should be - take tests from bug 234069 and upload them on WPT - so if we introduce this behavior - we don't regress leading to:

rdar://88359001

and then once test lands then do this changes and ensure that WPT passes.
Comment 6 Jon Jensen 2024-05-16 08:13:23 PDT
Opened a PR to add wpts around this: https://github.com/web-platform-tests/wpt/pull/46316
Comment 7 Ahmad Saleem 2024-05-16 08:14:49 PDT
(In reply to Jon Jensen from comment #6)
> Opened a PR to add wpts around this:
> https://github.com/web-platform-tests/wpt/pull/46316

Perfect! Once this get merged, I will add it to WebKit repo and then do PR to fix it and confirm whether it fixes everything and don't regress any behavior.
Comment 8 Ahmad Saleem 2024-05-17 09:21:40 PDT
Draft PR - https://github.com/WebKit/WebKit/pull/28713

^ I will check bit more locally to confirm it does not cause similar regression as in bug 239070

I synced the tests in bug 274277.
Comment 9 Ahmad Saleem 2024-05-17 09:36:15 PDT
(In reply to Ahmad Saleem from comment #8)
> Draft PR - https://github.com/WebKit/WebKit/pull/28713
> 
> ^ I will check bit more locally to confirm it does not cause similar
> regression as in bug 239070
> 
> I synced the tests in bug 274277.

I took tests from: https://github.com/web-platform-tests/wpt/pull/32916

and confirmed that they pass and don't lead to regression as in rdar://88359001.

Got following on local:

PASS Image submit button should submit the right coordinates on mouse clicks
PASS With multiple image submit buttons, the correct one should be used
Comment 10 EWS 2024-05-17 20:36:06 PDT
Committed 278944@main (69eafe9632ca): <https://commits.webkit.org/278944@main>

Reviewed commits have been landed. Closing PR #28713 and removing active labels.