LibWeb: Make HTMLInputElement of type number use the new double parser

This commit is contained in:
davidot 2022-10-12 02:24:05 +02:00 committed by Linus Groh
parent 8abd4f6102
commit 6e9969ded0
Notes: sideshowbarker 2024-07-18 04:38:32 +09:00

View file

@ -446,9 +446,10 @@ String HTMLInputElement::value_sanitization_algorithm(String value) const
}
} else if (type_state() == HTMLInputElement::TypeAttributeState::Number) {
// If the value of the element is not a valid floating-point number, then set it to the empty string instead.
char* end_ptr;
auto val = strtod(value.characters(), &end_ptr);
if (!isfinite(val) || *end_ptr)
// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#rules-for-parsing-floating-point-number-values
// 6. Skip ASCII whitespace within input given position.
auto maybe_double = value.to_double(TrimWhitespace::Yes);
if (!maybe_double.has_value() || !isfinite(maybe_double.value()))
return "";
}