mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibWeb: Refactor input range sanitization code use min and max getters
This commit is contained in:
parent
9165faca5e
commit
9b645d20b9
Notes:
sideshowbarker
2024-07-16 23:03:06 +09:00
Author: https://github.com/bplaat Commit: https://github.com/SerenityOS/serenity/commit/9b645d20b9 Pull-request: https://github.com/SerenityOS/serenity/pull/22944 Reviewed-by: https://github.com/AtkinsSJ Reviewed-by: https://github.com/shannonbooth Reviewed-by: https://github.com/trflynn89
1 changed files with 5 additions and 5 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue