1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-21 12:55:07 +00:00

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

View file

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