LibWeb: Validate form submissions whose submitter is not form-associated
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run

The spec for checking the no-validate state ends with a default return
value of "false". However, we were only hitting this case for form-
associated elements. If the submitter is the form itself, we want to
enter the form validation steps.
This commit is contained in:
Timothy Flynn 2025-08-15 08:56:14 -04:00 committed by Jelle Raaijmakers
commit 017ae80668
Notes: github-actions[bot] 2025-08-15 13:29:42 +00:00
2 changed files with 14 additions and 4 deletions

View file

@ -96,6 +96,16 @@ WebIDL::ExceptionOr<void> HTMLFormElement::implicitly_submit_form()
return {};
}
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-fs-novalidate
static bool novalidate_state(HTMLElement const& element)
{
// The no-validate state of an element is true if the element is a submit button and the element's formnovalidate
// attribute is present, or if the element's form owner's novalidate attribute is present, and false otherwise.
if (auto const* form_associated_element = as_if<FormAssociatedElement>(element))
return form_associated_element->novalidate_state();
return false;
}
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-form-submit
WebIDL::ExceptionOr<void> HTMLFormElement::submit_form(GC::Ref<HTMLElement> submitter, SubmitFormOptions options)
{
@ -142,8 +152,7 @@ WebIDL::ExceptionOr<void> HTMLFormElement::submit_form(GC::Ref<HTMLElement> subm
// 4. If the submitter element's no-validate state is false, then interactively validate the constraints
// of form and examine the result. If the result is negative (i.e., the constraint validation concluded
// that there were invalid fields and probably informed the user of this), then:
auto* form_associated_element = as_if<FormAssociatedElement>(*submitter);
if (form_associated_element && !form_associated_element->novalidate_state()) {
if (!novalidate_state(submitter)) {
auto validation_result = interactively_validate_constraints();
if (!validation_result) {
// 1. Set form's firing submission events to false.

View file

@ -2,6 +2,7 @@ Harness status: OK
Found 2 tests
2 Fail
1 Pass
1 Fail
Fail Validation for placeholder option
Fail Check form not submitted for invalid select
Pass Check form not submitted for invalid select