From 80434d46448f3b5d818864557ffd46d238132f30 Mon Sep 17 00:00:00 2001 From: elomscansio <163124154+elomscansio@users.noreply.github.com> Date: Sat, 22 Mar 2025 15:35:13 -0400 Subject: [PATCH] Fix form validation for readonly inputs and update WPT expectations (#36090) The HTML specification states that an input element with the `readonly` attribute must be barred from constraint validation. Our implementation previously included an extra check (`does_readonly_apply()`) to verify if `readonly` applies to the input type, which is unnecessary. This caused three test failures in: tests/wpt/meta/html/semantics/forms/constraints/form-validation-willValidate.html.ini - Removed `does_readonly_apply()` as it is not required for validation. - Removed `tests/wpt/meta/html/semantics/forms/constraints/form-validation-willValidate.html.ini` since the test now passes. To update the Web Platform Test expectations, see: https://book.servo.org/hacking/testing.html#updating-web-platform-test-expectations Fixes servo/servo#36076 Signed-off-by: Emmanuel Elom --- components/script/dom/htmlinputelement.rs | 20 +------------------ .../form-validation-willValidate.html.ini | 9 --------- 2 files changed, 1 insertion(+), 28 deletions(-) delete mode 100644 tests/wpt/meta/html/semantics/forms/constraints/form-validation-willValidate.html.ini diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index afd248710f4..930a07ffb68 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -477,24 +477,6 @@ impl HTMLInputElement { textinput.set_content(value); } - fn does_readonly_apply(&self) -> bool { - matches!( - self.input_type(), - InputType::Text | - InputType::Search | - InputType::Url | - InputType::Tel | - InputType::Email | - InputType::Password | - InputType::Date | - InputType::Month | - InputType::Week | - InputType::Time | - InputType::DatetimeLocal | - InputType::Number - ) - } - fn does_minmaxlength_apply(&self) -> bool { matches!( self.input_type(), @@ -2753,7 +2735,7 @@ impl Validatable for HTMLInputElement { InputType::Hidden | InputType::Button | InputType::Reset => false, _ => { !(self.upcast::().disabled_state() || - (self.ReadOnly() && self.does_readonly_apply()) || + self.ReadOnly() || is_barred_by_datalist_ancestor(self.upcast())) }, } diff --git a/tests/wpt/meta/html/semantics/forms/constraints/form-validation-willValidate.html.ini b/tests/wpt/meta/html/semantics/forms/constraints/form-validation-willValidate.html.ini deleted file mode 100644 index 959d7e9e98b..00000000000 --- a/tests/wpt/meta/html/semantics/forms/constraints/form-validation-willValidate.html.ini +++ /dev/null @@ -1,9 +0,0 @@ -[form-validation-willValidate.html] - [[INPUT in COLOR status\] Must be barred from the constraint validation if it is readonly] - expected: FAIL - - [[INPUT in FILE status\] Must be barred from the constraint validation if it is readonly] - expected: FAIL - - [[INPUT in SUBMIT status\] Must be barred from the constraint validation if it is readonly] - expected: FAIL