LibWeb: Validate time values when parsing transition value

This commit is contained in:
Tim Ledbetter 2025-03-12 17:56:04 +00:00 committed by Jelle Raaijmakers
commit 6298ec6be4
Notes: github-actions[bot] 2025-03-14 07:53:28 +00:00
3 changed files with 46 additions and 3 deletions

View file

@ -3791,13 +3791,18 @@ RefPtr<CSSStyleValue> Parser::parse_transition_value(TokenStream<ComponentValue>
auto time_value_count = 0; auto time_value_count = 0;
while (tokens.has_next_token() && !tokens.next_token().is(Token::Type::Comma)) { while (tokens.has_next_token() && !tokens.next_token().is(Token::Type::Comma)) {
if (auto time = parse_time(tokens); time.has_value()) { if (auto maybe_time = parse_time(tokens); maybe_time.has_value()) {
auto time = maybe_time.release_value();
switch (time_value_count) { switch (time_value_count) {
case 0: case 0:
transition.duration = time.release_value(); if (!time.is_calculated() && !property_accepts_time(PropertyID::TransitionDuration, time.value()))
return nullptr;
transition.duration = move(time);
break; break;
case 1: case 1:
transition.delay = time.release_value(); if (!time.is_calculated() && !property_accepts_time(PropertyID::TransitionDelay, time.value()))
return nullptr;
transition.delay = move(time);
break; break;
default: default:
dbgln_if(CSS_PARSER_DEBUG, "Transition property has more than two time values"); dbgln_if(CSS_PARSER_DEBUG, "Transition property has more than two time values");

View file

@ -0,0 +1,11 @@
Harness status: OK
Found 5 tests
3 Pass
2 Fail
Pass e.style['transition'] = "1s 2s 3s" should not set the property value
Pass e.style['transition'] = "-1s -2s" should not set the property value
Pass e.style['transition'] = "steps(1) steps(2)" should not set the property value
Fail e.style['transition'] = "none top" should not set the property value
Fail e.style['transition'] = "initial 1s" should not set the property value

View file

@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CSS Transitions: parsing transition with invalid values</title>
<link rel="help" href="https://drafts.csswg.org/css-transitions/#transition-shorthand-property">
<meta name="assert" content="transition supports only the grammar '<single-transition> #'.">
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="../../../css/support/parsing-testcommon.js"></script>
</head>
<body>
<script>
// <single-transition> = [ none | <single-transition-property> ] ||
// <time> || <easing-function> || <time>
test_invalid_value("transition", "1s 2s 3s");
test_invalid_value("transition", "-1s -2s");
test_invalid_value("transition", "steps(1) steps(2)");
test_invalid_value("transition", "none top");
test_invalid_value("transition", "initial 1s");
</script>
</body>
</html>