mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:18:11 +00:00
LibWeb: Implement input local date and time type sanitation algorithm
This commit is contained in:
parent
a3c4af7a19
commit
c5b953e51b
1 changed files with 25 additions and 0 deletions
|
@ -637,6 +637,26 @@ static bool is_valid_date_string(DeprecatedString const& value)
|
||||||
return day >= 1 && day <= AK::days_in_month(year, month);
|
return day >= 1 && day <= AK::days_in_month(year, month);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-local-date-and-time-string
|
||||||
|
static bool is_valid_local_date_and_time_string(DeprecatedString const& value)
|
||||||
|
{
|
||||||
|
auto parts_split_by_T = value.split('T');
|
||||||
|
if (parts_split_by_T.size() == 2)
|
||||||
|
return is_valid_date_string(parts_split_by_T[0]) && is_valid_time_string(parts_split_by_T[1]);
|
||||||
|
auto parts_split_by_space = value.split(' ');
|
||||||
|
if (parts_split_by_space.size() == 2)
|
||||||
|
return is_valid_date_string(parts_split_by_space[0]) && is_valid_time_string(parts_split_by_space[1]);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-normalised-local-date-and-time-string
|
||||||
|
static DeprecatedString normalize_local_date_and_time_string(DeprecatedString const& value)
|
||||||
|
{
|
||||||
|
VERIFY(value.count(" "sv) == 1);
|
||||||
|
return value.replace(" "sv, "T"sv, ReplaceMode::FirstOnly);
|
||||||
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/input.html#value-sanitization-algorithm
|
// https://html.spec.whatwg.org/multipage/input.html#value-sanitization-algorithm
|
||||||
DeprecatedString HTMLInputElement::value_sanitization_algorithm(DeprecatedString value) const
|
DeprecatedString HTMLInputElement::value_sanitization_algorithm(DeprecatedString value) const
|
||||||
{
|
{
|
||||||
|
@ -695,6 +715,11 @@ DeprecatedString HTMLInputElement::value_sanitization_algorithm(DeprecatedString
|
||||||
// https://html.spec.whatwg.org/multipage/input.html#time-state-(type=time):value-sanitization-algorithm
|
// https://html.spec.whatwg.org/multipage/input.html#time-state-(type=time):value-sanitization-algorithm
|
||||||
if (!is_valid_time_string(value))
|
if (!is_valid_time_string(value))
|
||||||
return "";
|
return "";
|
||||||
|
} else if (type_state() == HTMLInputElement::TypeAttributeState::LocalDateAndTime) {
|
||||||
|
// https://html.spec.whatwg.org/multipage/input.html#local-date-and-time-state-(type=datetime-local):value-sanitization-algorithm
|
||||||
|
if (is_valid_local_date_and_time_string(value))
|
||||||
|
return normalize_local_date_and_time_string(value);
|
||||||
|
return "";
|
||||||
} else if (type_state() == HTMLInputElement::TypeAttributeState::Color) {
|
} else if (type_state() == HTMLInputElement::TypeAttributeState::Color) {
|
||||||
// https://html.spec.whatwg.org/multipage/input.html#color-state-(type=color):value-sanitization-algorithm
|
// https://html.spec.whatwg.org/multipage/input.html#color-state-(type=color):value-sanitization-algorithm
|
||||||
// If the value of the element is a valid simple color, then set it to the value of the element converted to ASCII lowercase;
|
// If the value of the element is a valid simple color, then set it to the value of the element converted to ASCII lowercase;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue