LibWeb: Implement input email type sanitation algorithm

This commit is contained in:
Kyle Lanmon 2022-12-03 23:15:30 -06:00 committed by Linus Groh
parent 6fa34a4ee3
commit dfbc5553f2
Notes: sideshowbarker 2024-07-17 05:41:34 +09:00

View file

@ -506,6 +506,18 @@ DeprecatedString HTMLInputElement::value_sanitization_algorithm(DeprecatedString
}
return builder.string_view().trim(Infra::ASCII_WHITESPACE);
}
} else if (type_state() == HTMLInputElement::TypeAttributeState::Email) {
// https://html.spec.whatwg.org/multipage/input.html#email-state-(type=email):value-sanitization-algorithm
// FIXME: handle the `multiple` attribute
// Strip newlines from the value, then strip leading and trailing ASCII whitespace from the value.
if (value.contains('\r') || value.contains('\n')) {
StringBuilder builder;
for (auto c : value) {
if (!(c == '\r' || c == '\n'))
builder.append(c);
}
return builder.string_view().trim(Infra::ASCII_WHITESPACE);
}
} 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.
// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#rules-for-parsing-floating-point-number-values