1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:07:35 +00:00

LibWeb: Check parsed CSS values with property_accepts_value()

This brings us a few nice benefits:

- We only generate a `StyleValueList` for properties that accept
  multiple values.
- We reject declarations that have too many values.
- We check the type of each value that is parsed, to make sure it's
  acceptable to the property.

Probably there are some regressions here, since this is

Later, we can also replace many of the `is_foo()` functions and lambas
inside the Parser with more calls to `property_accepts_value()`. Also we
can remove some checks when resolving styles, since only valid types of
values will get to that point. But one step at a time. :^)
This commit is contained in:
Sam Atkins 2021-09-22 20:25:58 +01:00 committed by Andreas Kling
parent 11d3098f40
commit 5d6a4c5fc2

View file

@ -2872,22 +2872,25 @@ Result<NonnullRefPtr<StyleValue>, Parser::ParsingResult> Parser::parse_css_value
}
if (component_values.size() == 1) {
if (auto parsed_value = parse_css_value(m_context, component_values.first()))
return parsed_value.release_nonnull();
if (auto parsed_value = parse_css_value(m_context, component_values.first())) {
if (property_accepts_value(property_id, *parsed_value))
return parsed_value.release_nonnull();
}
return ParsingResult::SyntaxError;
}
// We have multiple values, so treat them as a StyleValueList.
// FIXME: Specify in Properties.json whether to permit this for each property.
NonnullRefPtrVector<StyleValue> parsed_values;
for (auto& component_value : component_values) {
auto parsed = parse_css_value(m_context, component_value);
if (!parsed)
return ParsingResult::SyntaxError;
parsed_values.append(parsed.release_nonnull());
if (property_maximum_value_count(property_id) > 1) {
NonnullRefPtrVector<StyleValue> parsed_values;
for (auto& component_value : component_values) {
auto parsed_value = parse_css_value(m_context, component_value);
if (!parsed_value || !property_accepts_value(property_id, *parsed_value))
return ParsingResult::SyntaxError;
parsed_values.append(parsed_value.release_nonnull());
}
if (!parsed_values.is_empty() && parsed_values.size() <= property_maximum_value_count(property_id))
return { StyleValueList::create(move(parsed_values)) };
}
if (!parsed_values.is_empty())
return { StyleValueList::create(move(parsed_values)) };
return ParsingResult::SyntaxError;
}