LibWeb/CSS: Interpret NaN as 0 when resolving alpha and rgb values

Fixes the crash in css/css-color/parsing/color-valid-hwb.html.

The crash was probably introduced in 248e4bb5, as it was the first
commit to VERIFY that the value given to `Color::with_opacity` were in
the correct range. As the values in color-valid-hwb.html were resolved
as NaN, the check never passed.
This commit is contained in:
Lucas CHOLLET 2024-12-02 23:59:57 -05:00 committed by Sam Atkins
commit 6804ce348e
Notes: github-actions[bot] 2024-12-04 16:12:33 +00:00
4 changed files with 121 additions and 0 deletions

View file

@ -18,6 +18,8 @@ Color CSSRGB::to_color(Optional<Layout::NodeWithStyle const&>) const
auto resolve_rgb_to_u8 = [](CSSStyleValue const& style_value) -> Optional<u8> {
// <number> | <percentage> | none
auto normalized = [](double number) {
if (isnan(number))
number = 0;
return llround(clamp(number, 0.0, 255.0));
};