LibWeb: Don't crash if IntersectionObserver root margin has invalid unit

This commit is contained in:
Tim Ledbetter
2025-12-15 22:34:03 +00:00
committed by Sam Atkins
parent da92e1a054
commit 1a1321d160
Notes: github-actions[bot] 2025-12-16 11:24:29 +00:00
2 changed files with 10 additions and 5 deletions

View File

@@ -342,14 +342,15 @@ Optional<Vector<CSS::LengthPercentage>> IntersectionObserver::parse_a_margin(JS:
for (auto const& token : tokens) {
// If token is an absolute length dimension token, replace it with a an equivalent pixel length.
if (token.is(CSS::Parser::Token::Type::Dimension)) {
auto length = CSS::Length(token.token().dimension_value(), CSS::string_to_length_unit(token.token().dimension_unit()).value());
if (length.is_absolute()) {
tokens_length_percentage.append(length);
continue;
if (auto length_unit = CSS::string_to_length_unit(token.token().dimension_unit()); length_unit.has_value()) {
if (auto length = CSS::Length(token.token().dimension_value(), length_unit.release_value()); length.is_absolute()) {
tokens_length_percentage.append(length);
continue;
}
}
}
// If token is a <percentage> token, replace it with an equivalent percentage.
if (token.is(CSS::Parser::Token::Type::Percentage)) {
else if (token.is(CSS::Parser::Token::Type::Percentage)) {
tokens_length_percentage.append(CSS::Percentage(token.token().percentage()));
continue;
}