Skip to content

Truly independent web browser

LibWeb: Always give an empty number input a value when stepping it

Andreas Kling22c2b9fc8770
diff --git a/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Libraries/LibWeb/HTML/HTMLInputElement.cpp
index e0b0b05f9e6..aec4c997480 100644
--- a/Libraries/LibWeb/HTML/HTMLInputElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLInputElement.cpp
@@ -3390,7 +3390,8 @@ WebIDL::ExceptionOr<void> HTMLInputElement::step_up_or_down(bool is_down, WebIDL
// 5. If applying the algorithm to convert a string to a number to the string given by the element's value does not result in an error,
// then let value be the result of that algorithm. Otherwise, let value be zero.
- double value = convert_string_to_number(this->value()).value_or(0);
+ auto maybe_value = convert_string_to_number(this->value());
+ double value = maybe_value.value_or(0);
// 6. Let valueBeforeStepping be value.
double value_before_stepping = value;
@@ -3434,11 +3435,12 @@ WebIDL::ExceptionOr<void> HTMLInputElement::step_up_or_down(bool is_down, WebIDL
// 10. If either the method invoked was the stepDown() method and value is greater than valueBeforeStepping,
// or the method invoked was the stepUp() method and value is less than valueBeforeStepping, then return.
- if (is_down) {
- if (value > value_before_stepping)
+ // INTEROP: Browsers only do this when the element's value could be converted to a number, so stepping an
+ // element without a value always gives it one.
+ if (maybe_value.has_value()) {
+ if (is_down && value > value_before_stepping)
return {};
- } else {
- if (value < value_before_stepping)
+ if (!is_down && value < value_before_stepping)
return {};
}
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/input-stepdown-02.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/input-stepdown-02.txt
index 5097b7cbe5c..9c7ad22988d 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/input-stepdown-02.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/input-stepdown-02.txt
@@ -2,10 +2,9 @@ Harness status: OK
Found 6 tests
-5 Pass
-1 Fail
+6 Pass
Pass stepDown() on input with no initial or min values
-Fail stepDown() on input with no initial value and positive min value
+Pass stepDown() on input with no initial value and positive min value
Pass stepDown() on input with no initial value and negative min value
Pass stepDown() on input with initial value equal to min value
Pass stepDown() on input with initial value less than min value