From c2cc0d9cd0a8a24b4f9962eb3cce880c74e67127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20Mu=C3=B1oz=20Mazur?= Date: Tue, 14 Jan 2025 13:16:25 -0400 Subject: [PATCH] LibWeb: Check if input is disabled before submit event to form --- Libraries/LibWeb/HTML/HTMLInputElement.cpp | 14 +++++++++++++- .../wpt-import/dom/events/Event-dispatch-click.txt | 9 ++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Libraries/LibWeb/HTML/HTMLInputElement.cpp index 6e2cc6fc8c6..9cd3712f744 100644 --- a/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -6,6 +6,7 @@ * Copyright (c) 2023, Bastiaan van der Plaat * Copyright (c) 2024, Jelle Raaijmakers * Copyright (c) 2024, Fernando Kiotheka + * Copyright (c) 2025, Felipe Muñoz Mazur * * SPDX-License-Identifier: BSD-2-Clause */ @@ -376,8 +377,15 @@ WebIDL::ExceptionOr HTMLInputElement::run_input_activation_behavior(DOM::E auto change_event = DOM::Event::create(realm(), HTML::EventNames::change); change_event->set_bubbles(true); dispatch_event(*change_event); - } else if (type_state() == TypeAttributeState::SubmitButton) { + } + // https://html.spec.whatwg.org/multipage/input.html#submit-button-state-(type=submit) + else if (type_state() == TypeAttributeState::SubmitButton) { GC::Ptr form; + + // The input element represents a button that, when activated, submits the form. + if (is_actually_disabled()) + return {}; + // 1. If the element does not have a form owner, then return. if (!(form = this->form())) return {}; @@ -418,6 +426,10 @@ WebIDL::ExceptionOr HTMLInputElement::run_input_activation_behavior(DOM::E } // https://html.spec.whatwg.org/multipage/input.html#reset-button-state-(type=reset) else if (type_state() == TypeAttributeState::ResetButton) { + // The input element represents a button that, when activated, resets the form. + if (is_actually_disabled()) + return {}; + // 1. If the element does not have a form owner, then return. auto* form = this->form(); if (!form) diff --git a/Tests/LibWeb/Text/expected/wpt-import/dom/events/Event-dispatch-click.txt b/Tests/LibWeb/Text/expected/wpt-import/dom/events/Event-dispatch-click.txt index 3a9d674a1dd..8738db5c47e 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/dom/events/Event-dispatch-click.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/dom/events/Event-dispatch-click.txt @@ -2,8 +2,7 @@ Harness status: OK Found 33 tests -30 Pass -3 Fail +33 Pass Pass basic with click() Pass basic with dispatchEvent() Pass basic with wrong event class @@ -34,6 +33,6 @@ Pass disabling checkbox in onclick listener shouldn't suppress onchange Pass disabling radio in onclick listener shouldn't suppress oninput Pass disabling radio in onclick listener shouldn't suppress onchange Pass disconnected form should not submit -Fail disabled submit button should not activate -Fail submit button should not activate if the event listener disables it -Fail submit button that morphed from checkbox should not activate \ No newline at end of file +Pass disabled submit button should not activate +Pass submit button should not activate if the event listener disables it +Pass submit button that morphed from checkbox should not activate \ No newline at end of file