Changeset 293444 in webkit


Ignore:
Timestamp:
Apr 26, 2022 12:31:41 PM (3 months ago)
Author:
Ziran Sun
Message:

Constructed FormData object should not contain an entry for the submit button that was used to submit the form
https://bugs.webkit.org/show_bug.cgi?id=239070

Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

Update test expectation as the sub-test is now passing.

  • web-platform-tests/html/semantics/forms/form-submission-0/constructing-form-data-set-expected.txt:

Source/WebCore:

When the activedSubmit flag is set for a submit button, its value is appended to a FormData. In the case of form
submission called in submit event handler, we include submit button when build FormData. The submit button should
not be included though. This patch correct it by calling set the activatedSubmit flag just before or after building
FormData.

Part of the patch is an import of Chromium CL at
https://codereview.chromium.org/2340213002

  • html/DOMFormData.cpp:

(WebCore::DOMFormData::create):

  • html/HTMLButtonElement.cpp:

(WebCore::HTMLButtonElement::defaultEventHandler):

  • html/HTMLFormElement.cpp:

(WebCore::HTMLFormElement::submit):
(WebCore::HTMLFormElement::constructEntryList):

  • html/HTMLFormElement.h:
  • html/SubmitInputType.cpp:

(WebCore::SubmitInputType::handleDOMActivateEvent):

  • loader/FormSubmission.cpp:

(WebCore::FormSubmission::create):

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r293418 r293444  
     12022-04-26  Ziran Sun  <zsun@igalia.com>
     2
     3        Constructed FormData object should not contain an entry for the submit button that was used to submit the form
     4        https://bugs.webkit.org/show_bug.cgi?id=239070
     5
     6        Reviewed by Chris Dumez.
     7
     8        Update test expectation as the sub-test is now passing.
     9        * web-platform-tests/html/semantics/forms/form-submission-0/constructing-form-data-set-expected.txt:
     10
    1112022-04-26  Youenn Fablet  <youenn@apple.com>
    212
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/form-submission-0/constructing-form-data-set-expected.txt

    r288955 r293444  
    2222PASS Entries added to "formData" IDL attribute should be submitted.
    2323PASS Entries added to the "formdata" IDL attribute shouldn't be newline normalized in the resulting FormData
    24 FAIL The constructed FormData object should not contain an entry for the submit button that was used to submit the form. assert_false: expected false got true
     24PASS The constructed FormData object should not contain an entry for the submit button that was used to submit the form.
    2525
  • trunk/Source/WebCore/ChangeLog

    r293443 r293444  
     12022-04-26  Ziran Sun  <zsun@igalia.com>
     2
     3        Constructed FormData object should not contain an entry for the submit button that was used to submit the form
     4        https://bugs.webkit.org/show_bug.cgi?id=239070
     5
     6        Reviewed by Chris Dumez.
     7
     8        When the activedSubmit flag is set for a submit button, its value is appended to a FormData. In the case of form
     9        submission called in submit event handler, we include submit button when build FormData. The submit button should
     10        not be included though. This patch correct it by calling set the activatedSubmit flag just before or after building
     11        FormData.
     12       
     13        Part of the patch is an import of Chromium CL at
     14        https://codereview.chromium.org/2340213002
     15
     16        * html/DOMFormData.cpp:
     17        (WebCore::DOMFormData::create):
     18        * html/HTMLButtonElement.cpp:
     19        (WebCore::HTMLButtonElement::defaultEventHandler):
     20        * html/HTMLFormElement.cpp:
     21        (WebCore::HTMLFormElement::submit):
     22        (WebCore::HTMLFormElement::constructEntryList):
     23        * html/HTMLFormElement.h:
     24        * html/SubmitInputType.cpp:
     25        (WebCore::SubmitInputType::handleDOMActivateEvent):
     26        * loader/FormSubmission.cpp:
     27        (WebCore::FormSubmission::create):
     28
    1292022-04-26  Simon Fraser  <simon.fraser@apple.com>
    230
  • trunk/Source/WebCore/html/DOMFormData.cpp

    r286772 r293444  
    4949        return formData;
    5050   
    51     auto result = form->constructEntryList(WTFMove(formData), nullptr);
     51    auto result = form->constructEntryList(nullptr, WTFMove(formData), nullptr);
    5252   
    5353    if (!result)
  • trunk/Source/WebCore/html/HTMLButtonElement.cpp

    r293285 r293444  
    142142
    143143            if (auto currentForm = form()) {
    144                 if (m_type == SUBMIT) {
    145                     SetForScope activatedSubmitState(m_isActivatedSubmit, true);
     144                if (m_type == SUBMIT)
    146145                    currentForm->submitIfPossible(&event, this);
    147                 }
    148146
    149147                if (m_type == RESET)
  • trunk/Source/WebCore/html/HTMLFormElement.cpp

    r293309 r293444  
    324324
    325325    if (m_shouldSubmit)
    326         submit(event, true, !submitter, trigger, submitter);
     326        submit(event, !submitter, trigger, submitter);
    327327}
    328328
    329329void HTMLFormElement::submit()
    330330{
    331     submit(nullptr, false, true, NotSubmittedByJavaScript);
     331    submit(nullptr, true, NotSubmittedByJavaScript);
    332332}
    333333
    334334void HTMLFormElement::submitFromJavaScript()
    335335{
    336     submit(nullptr, false, UserGestureIndicator::processingUserGesture(), SubmittedByJavaScript);
     336    submit(nullptr, UserGestureIndicator::processingUserGesture(), SubmittedByJavaScript);
    337337}
    338338
     
    394394}
    395395
    396 void HTMLFormElement::submit(Event* event, bool activateSubmitButton, bool processingUserGesture, FormSubmissionTrigger trigger, HTMLFormControlElement* submitter)
     396void HTMLFormElement::submit(Event* event, bool processingUserGesture, FormSubmissionTrigger trigger, HTMLFormControlElement* submitter)
    397397{
    398398    // The submitIfPossible function also does this check, but we need to do it here
     
    417417    m_wasUserSubmitted = processingUserGesture;
    418418
    419     auto firstSuccessfulSubmitButton = findSubmitButton(submitter, activateSubmitButton);
    420     if (firstSuccessfulSubmitButton)
    421         firstSuccessfulSubmitButton->setActivatedSubmit(true);
     419    if (event && !submitter) {
     420        // In a case of implicit submission without a submit button, 'submit' event handler might add a submit button. We search for a submit button again.
     421        auto associatedElements = copyAssociatedElementsVector();
     422        for (auto& element : associatedElements) {
     423            if (auto* control = dynamicDowncast<HTMLFormControlElement>(element.get()); control && control->isSuccessfulSubmitButton()) {
     424                submitter = control;
     425                break;
     426            }
     427        }
     428    }
    422429
    423430    Ref protectedThis { *this }; // Form submission can execute arbitary JavaScript.
     
    444451    else
    445452        frame->loader().submitForm(WTFMove(formSubmission));
    446 
    447     if (firstSuccessfulSubmitButton)
    448         firstSuccessfulSubmitButton->setActivatedSubmit(false);
    449453
    450454    m_shouldSubmit = false;
     
    10171021}
    10181022
    1019 RefPtr<DOMFormData> HTMLFormElement::constructEntryList(Ref<DOMFormData>&& domFormData, StringPairVector* formValues)
     1023RefPtr<DOMFormData> HTMLFormElement::constructEntryList(RefPtr<HTMLFormControlElement>&& submitter, Ref<DOMFormData>&& domFormData, StringPairVector* formValues)
    10201024{
    10211025    // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#constructing-form-data-set
     
    10261030   
    10271031    SetForScope isConstructingEntryListScope(m_isConstructingEntryList, true);
     1032
     1033    if (submitter)
     1034        submitter->setActivatedSubmit(true);
    10281035   
    10291036    for (auto& control : this->copyAssociatedElementsVector()) {
     
    10411048   
    10421049    dispatchEvent(FormDataEvent::create(eventNames().formdataEvent, Event::CanBubble::Yes, Event::IsCancelable::No, Event::IsComposed::No, domFormData.copyRef()));
     1050
     1051    if (submitter)
     1052        submitter->setActivatedSubmit(false);
    10431053   
    10441054    return domFormData->clone();
  • trunk/Source/WebCore/html/HTMLFormElement.h

    r292960 r293444  
    128128    static HTMLFormElement* findClosestFormAncestor(const Element&);
    129129   
    130     RefPtr<DOMFormData> constructEntryList(Ref<DOMFormData>&&, StringPairVector*);
     130    RefPtr<DOMFormData> constructEntryList(RefPtr<HTMLFormControlElement>&&, Ref<DOMFormData>&&, StringPairVector*);
    131131   
    132132private:
     
    147147    void copyNonAttributePropertiesFromElement(const Element&) final;
    148148
    149     void submit(Event*, bool activateSubmitButton, bool processingUserGesture, FormSubmissionTrigger, HTMLFormControlElement* submitter = nullptr);
     149    void submit(Event*, bool processingUserGesture, FormSubmissionTrigger, HTMLFormControlElement* submitter = nullptr);
    150150
    151151    void submitDialog(Ref<FormSubmission>&&);
  • trunk/Source/WebCore/html/SubmitInputType.cpp

    r288955 r293444  
    7575    protectedElement->document().updateLayoutIgnorePendingStylesheets();
    7676
    77     protectedElement->setActivatedSubmit(true);
    7877    if (RefPtr currentForm = protectedElement->form())
    7978        currentForm->submitIfPossible(&event, element()); // Event handlers can run.
    80     protectedElement->setActivatedSubmit(false);
    8179    event.setDefaultHandled();
    8280}
  • trunk/Source/WebCore/loader/FormSubmission.cpp

    r293326 r293444  
    214214    StringPairVector formValues;
    215215
    216     auto result = form.constructEntryList(WTFMove(domFormData), &formValues);
     216    auto result = form.constructEntryList(submitter.copyRef(), WTFMove(domFormData), &formValues);
    217217    RELEASE_ASSERT(result);
    218218    domFormData = result.releaseNonNull();
Note: See TracChangeset for help on using the changeset viewer.