Skip to content
Permalink
Browse files
Hidden buttons can't be used as the submitter in an implicit submission
https://bugs.webkit.org/show_bug.cgi?id=247545

Reviewed by Chris Dumez.

Removed the check for renderer to match the behaviors of other browsers and HTML5 spec:
https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#implicit-submission

* LayoutTests/fast/forms/submit-form-with-hidden-button-expected.txt: Added.
* LayoutTests/fast/forms/submit-form-with-hidden-button.html: Added.
* Source/WebCore/html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::submitImplicitly):

Canonical link: https://commits.webkit.org/256813@main
  • Loading branch information
rniwa committed Nov 18, 2022
1 parent 82b82f5 commit ad3421ff11860bb575db3e52f74c4edb128a9169
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
@@ -0,0 +1,10 @@
Tests implicitly submitting with a hidden button.

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


PASS submitter.id is "hiddenButton"
PASS successfullyParsed is true

TEST COMPLETE

@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<body>
<form id="form">
<input id="text1" name="text1" value="Press Enter" autofocus>
<input id="hiddenButton" type="submit" name="hiddenButton" value="Success" hidden>
<input id="secondButton" type="submit" name="secondButton" value="Fail" style="visibility: hidden">
</form>
<script src="../../resources/js-test.js"></script>
<script>
description('Tests implicitly submitting with a hidden button.');

let submitter = null;
form.addEventListener("submit", event => {
submitter = event.submitter;
event.preventDefault();
});

text1.focus();

const enterKeyEvent = new KeyboardEvent('keypress', { bubbles: true, cancelable: true, view: window, detail: 0,
key: 'Enter', code: 'Enter', keyIdentifier: '', keyCode: 13, charCode: 13, which: 13,
location: 0, ctrlKey: false, altKey: false, shiftKey: false, metaKey: false });
text1.dispatchEvent(enterKeyEvent);

shouldBeEqualToString('submitter.id', 'hiddenButton');

</script>
</body>
</html>
@@ -228,10 +228,8 @@ void HTMLFormElement::submitImplicitly(Event& event, bool fromImplicitSubmission
continue;
HTMLFormControlElement& formElement = downcast<HTMLFormControlElement>(*listedElement);
if (formElement.isSuccessfulSubmitButton()) {
if (formElement.renderer()) {
formElement.dispatchSimulatedClick(&event);
return;
}
formElement.dispatchSimulatedClick(&event);
return;
} else if (formElement.canTriggerImplicitSubmission())
++submissionTriggerCount;
}

0 comments on commit ad3421f

Please sign in to comment.