mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-27 21:21:50 +03:00
LibWeb: Bounds-check parsed CSS types
This reintroduces bounds-checking for the CSS `<angle>`, `<frequency>`,
`<integer>`, `<length>`, `<number>`, `<percentage>`, `<resolution>`,
and `<time>` types.
I regressed this around 6b8f484114
when
changing how we parsed StyleValues.
This is an improvement from before though, since we now allow the bounds
of a dimension type to have units.
Added a test to make sure we don't regress this again. :^)
This commit is contained in:
parent
51f75d7071
commit
1f2629f132
Notes:
sideshowbarker
2024-07-16 19:24:07 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/1f2629f132 Pull-request: https://github.com/SerenityOS/serenity/pull/19223
8
Tests/LibWeb/Layout/expected/negative-max-size.txt
Normal file
8
Tests/LibWeb/Layout/expected/negative-max-size.txt
Normal file
@ -0,0 +1,8 @@
|
||||
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
|
||||
BlockContainer <html> at (0,0) content-size 800x35.46875 [BFC] children: not-inline
|
||||
BlockContainer <body> at (8,8) content-size 784x19.46875 children: not-inline
|
||||
BlockContainer <div> at (9,9) content-size 782x17.46875 children: inline
|
||||
line 0 width: 147.1875, height: 17.46875, bottom: 17.46875, baseline: 13.53125
|
||||
frag 0 from TextNode start: 0, length: 20, rect: [9,9 147.1875x17.46875]
|
||||
"Well, hello friends!"
|
||||
TextNode <#text>
|
9
Tests/LibWeb/Layout/input/negative-max-size.html
Normal file
9
Tests/LibWeb/Layout/input/negative-max-size.html
Normal file
@ -0,0 +1,9 @@
|
||||
<!doctype html><style>
|
||||
* {
|
||||
font: 16px SerenitySans;
|
||||
}
|
||||
div {
|
||||
border: 1px solid black;
|
||||
max-width: -90px;
|
||||
}
|
||||
</style><div>Well, hello friends!</div>
|
@ -7589,19 +7589,20 @@ ErrorOr<Parser::PropertyAndValue> Parser::parse_css_value_for_properties(Readonl
|
||||
|
||||
if (peek_token.is(Token::Type::Number) && property_accepts_numeric) {
|
||||
if (property_accepting_integer.has_value()) {
|
||||
if (auto integer = TRY(parse_integer_value(tokens)))
|
||||
if (auto integer = TRY(parse_integer_value(tokens)); integer && property_accepts_integer(*property_accepting_integer, integer->as_integer().integer()))
|
||||
return PropertyAndValue { *property_accepting_integer, integer };
|
||||
}
|
||||
if (property_accepting_number.has_value()) {
|
||||
if (auto number = TRY(parse_number_value(tokens)))
|
||||
if (auto number = TRY(parse_number_value(tokens)); number && property_accepts_number(*property_accepting_number, number->as_number().number()))
|
||||
return PropertyAndValue { *property_accepting_number, number };
|
||||
}
|
||||
}
|
||||
|
||||
if (peek_token.is(Token::Type::Percentage)) {
|
||||
if (auto property = any_property_accepts_type(property_ids, ValueType::Percentage); property.has_value()) {
|
||||
auto percentage = Percentage(peek_token.token().percentage());
|
||||
if (auto property = any_property_accepts_type(property_ids, ValueType::Percentage); property.has_value() && property_accepts_percentage(*property, percentage)) {
|
||||
(void)tokens.next_token();
|
||||
return PropertyAndValue { *property, TRY(PercentageStyleValue::create(Percentage(peek_token.token().percentage()))) };
|
||||
return PropertyAndValue { *property, TRY(PercentageStyleValue::create(percentage)) };
|
||||
}
|
||||
}
|
||||
|
||||
@ -7635,24 +7636,29 @@ ErrorOr<Parser::PropertyAndValue> Parser::parse_css_value_for_properties(Readonl
|
||||
(void)tokens.next_token();
|
||||
auto dimension = maybe_dimension.release_value();
|
||||
if (dimension.is_angle()) {
|
||||
if (auto property = any_property_accepts_type(property_ids, ValueType::Angle); property.has_value())
|
||||
return PropertyAndValue { *property, TRY(AngleStyleValue::create(dimension.angle())) };
|
||||
auto angle = dimension.angle();
|
||||
if (auto property = any_property_accepts_type(property_ids, ValueType::Angle); property.has_value() && property_accepts_angle(*property, angle))
|
||||
return PropertyAndValue { *property, TRY(AngleStyleValue::create(angle)) };
|
||||
}
|
||||
if (dimension.is_frequency()) {
|
||||
if (auto property = any_property_accepts_type(property_ids, ValueType::Frequency); property.has_value())
|
||||
return PropertyAndValue { *property, TRY(FrequencyStyleValue::create(dimension.frequency())) };
|
||||
auto frequency = dimension.frequency();
|
||||
if (auto property = any_property_accepts_type(property_ids, ValueType::Frequency); property.has_value() && property_accepts_frequency(*property, frequency))
|
||||
return PropertyAndValue { *property, TRY(FrequencyStyleValue::create(frequency)) };
|
||||
}
|
||||
if (dimension.is_length()) {
|
||||
if (auto property = any_property_accepts_type(property_ids, ValueType::Length); property.has_value())
|
||||
return PropertyAndValue { *property, TRY(LengthStyleValue::create(dimension.length())) };
|
||||
auto length = dimension.length();
|
||||
if (auto property = any_property_accepts_type(property_ids, ValueType::Length); property.has_value() && property_accepts_length(*property, length))
|
||||
return PropertyAndValue { *property, TRY(LengthStyleValue::create(length)) };
|
||||
}
|
||||
if (dimension.is_resolution()) {
|
||||
if (auto property = any_property_accepts_type(property_ids, ValueType::Resolution); property.has_value())
|
||||
return PropertyAndValue { *property, TRY(ResolutionStyleValue::create(dimension.resolution())) };
|
||||
auto resolution = dimension.resolution();
|
||||
if (auto property = any_property_accepts_type(property_ids, ValueType::Resolution); property.has_value() && property_accepts_resolution(*property, resolution))
|
||||
return PropertyAndValue { *property, TRY(ResolutionStyleValue::create(resolution)) };
|
||||
}
|
||||
if (dimension.is_time()) {
|
||||
if (auto property = any_property_accepts_type(property_ids, ValueType::Time); property.has_value())
|
||||
return PropertyAndValue { *property, TRY(TimeStyleValue::create(dimension.time())) };
|
||||
auto time = dimension.time();
|
||||
if (auto property = any_property_accepts_type(property_ids, ValueType::Time); property.has_value() && property_accepts_time(*property, time))
|
||||
return PropertyAndValue { *property, TRY(TimeStyleValue::create(time)) };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user