LibWeb: Don't crash when normalizing a local datetime with a T separator

This commit is contained in:
Tim Ledbetter 2024-09-10 10:44:18 +01:00 committed by Tim Ledbetter
parent eb4e40bc49
commit 2d7547921b
Notes: github-actions[bot] 2024-09-10 15:14:05 +00:00

View file

@ -160,8 +160,13 @@ bool is_valid_local_date_and_time_string(StringView value)
// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-normalised-local-date-and-time-string
String normalize_local_date_and_time_string(String const& value)
{
VERIFY(value.count(" "sv) == 1);
return MUST(value.replace(" "sv, "T"sv, ReplaceMode::FirstOnly));
if (auto spaces = value.count(" "sv); spaces > 0) {
VERIFY(spaces == 1);
return MUST(value.replace(" "sv, "T"sv, ReplaceMode::FirstOnly));
}
VERIFY(value.count("T"sv) == 1);
return value;
}
// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-time-string