mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-03 21:10:30 +00:00
LibWeb: Implement input local date and time type sanitation algorithm
This commit is contained in:
parent
a3c4af7a19
commit
c5b953e51b
Notes:
sideshowbarker
2024-07-17 03:09:45 +09:00
Author: https://github.com/lanmonster Commit: https://github.com/SerenityOS/serenity/commit/c5b953e51b Pull-request: https://github.com/SerenityOS/serenity/pull/16320 Reviewed-by: https://github.com/linusg ✅
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);
|
||||
}
|
||||
|
||||
// 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
|
||||
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
|
||||
if (!is_valid_time_string(value))
|
||||
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) {
|
||||
// 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;
|
||||
|
|
Loading…
Reference in a new issue