From 9b645d20b96c0acc1189117cc782a1dece5f3a32 Mon Sep 17 00:00:00 2001 From: Bastiaan van der Plaat Date: Mon, 26 Feb 2024 20:54:09 +0100 Subject: [PATCH] LibWeb: Refactor input range sanitization code use min and max getters --- Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp index 2a7b2c8f0c..09cb4db062 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -1207,11 +1207,11 @@ String HTMLInputElement::value_sanitization_algorithm(String const& value) const auto maybe_value = parse_floating_point_number(value); if (!maybe_value.has_value() || !isfinite(maybe_value.value())) { // The default value is the minimum plus half the difference between the minimum and the maximum, unless the maximum is less than the minimum, in which case the default value is the minimum. - auto min = parse_floating_point_number(get_attribute(HTML::AttributeNames::min).value_or("0"_string)).value_or(0); - auto max = parse_floating_point_number(get_attribute(HTML::AttributeNames::max).value_or("1"_string)).value_or(1); - if (max > min) - return JS::number_to_string(min); - return JS::number_to_string(min + (max - min) / 2); + auto minimum = *min(); + auto maximum = *max(); + if (maximum > minimum) + return JS::number_to_string(minimum); + return JS::number_to_string(minimum + (maximum - minimum) / 2); } } else if (type_state() == HTMLInputElement::TypeAttributeState::Color) { // https://html.spec.whatwg.org/multipage/input.html#color-state-(type=color):value-sanitization-algorithm