From 017ae80668760dcfd0f3542f8f62f4ea651ea74e Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Fri, 15 Aug 2025 08:56:14 -0400 Subject: [PATCH] LibWeb: Validate form submissions whose submitter is not form-associated 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. --- Libraries/LibWeb/HTML/HTMLFormElement.cpp | 13 +++++++++++-- .../select-validity.tentative.txt | 5 +++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Libraries/LibWeb/HTML/HTMLFormElement.cpp b/Libraries/LibWeb/HTML/HTMLFormElement.cpp index 940831f0ba2..a742628061d 100644 --- a/Libraries/LibWeb/HTML/HTMLFormElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLFormElement.cpp @@ -96,6 +96,16 @@ WebIDL::ExceptionOr 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(element)) + return form_associated_element->novalidate_state(); + return false; +} + // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-form-submit WebIDL::ExceptionOr HTMLFormElement::submit_form(GC::Ref submitter, SubmitFormOptions options) { @@ -142,8 +152,7 @@ WebIDL::ExceptionOr HTMLFormElement::submit_form(GC::Ref 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(*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. diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-select-element/select-validity.tentative.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-select-element/select-validity.tentative.txt index 5bd064f61dc..9737542e200 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-select-element/select-validity.tentative.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-select-element/select-validity.tentative.txt @@ -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 \ No newline at end of file +Pass Check form not submitted for invalid select \ No newline at end of file