From ea0e434d1d6b464ab0a56c4b7150950be78ae7d3 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Thu, 21 Nov 2024 13:09:47 +0000 Subject: [PATCH] LibWeb: Allow FormData entry list to be mutated within a FormDataEvent Previously, the list was copied when constructing the FormData object, then the original list was passed to the event, meaning any changes to the list that happened within the event would not be reflected outside of it. --- .../LibWeb/HTML/FormControlInfrastructure.cpp | 4 ++-- .../HTML/form-add-dynamic-formdata.txt | 2 ++ .../input/HTML/form-add-dynamic-formdata.html | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/HTML/form-add-dynamic-formdata.txt create mode 100644 Tests/LibWeb/Text/input/HTML/form-add-dynamic-formdata.html diff --git a/Libraries/LibWeb/HTML/FormControlInfrastructure.cpp b/Libraries/LibWeb/HTML/FormControlInfrastructure.cpp index 848621e9e62..ddbd17b00b6 100644 --- a/Libraries/LibWeb/HTML/FormControlInfrastructure.cpp +++ b/Libraries/LibWeb/HTML/FormControlInfrastructure.cpp @@ -201,7 +201,7 @@ WebIDL::ExceptionOr>> construct_entry_list(J } } // 6. Let form data be a new FormData object associated with entry list. - auto form_data = TRY(XHR::FormData::construct_impl(realm, entry_list)); + auto form_data = TRY(XHR::FormData::construct_impl(realm, move(entry_list))); // 7. Fire an event named formdata at form using FormDataEvent, with the formData attribute initialized to form data and the bubbles attribute initialized to true. FormDataEventInit init {}; @@ -214,7 +214,7 @@ WebIDL::ExceptionOr>> construct_entry_list(J form.set_constructing_entry_list(false); // 9. Return a clone of entry list. - return entry_list; + return form_data->entry_list(); } ErrorOr normalize_line_breaks(StringView value) diff --git a/Tests/LibWeb/Text/expected/HTML/form-add-dynamic-formdata.txt b/Tests/LibWeb/Text/expected/HTML/form-add-dynamic-formdata.txt new file mode 100644 index 00000000000..8447c6d8dcb --- /dev/null +++ b/Tests/LibWeb/Text/expected/HTML/form-add-dynamic-formdata.txt @@ -0,0 +1,2 @@ +formData.get('field1') === 'value1': true +formData.get('field2') === 'value2': true diff --git a/Tests/LibWeb/Text/input/HTML/form-add-dynamic-formdata.html b/Tests/LibWeb/Text/input/HTML/form-add-dynamic-formdata.html new file mode 100644 index 00000000000..e808ca226fe --- /dev/null +++ b/Tests/LibWeb/Text/input/HTML/form-add-dynamic-formdata.html @@ -0,0 +1,19 @@ + +
+ +
+ +