LibWeb: Don't crash on percentage values for CSS stroke-width

Fixes a crash when loading https://vercel.com/
This commit is contained in:
Andreas Kling 2023-05-21 09:50:56 +02:00
parent beb55f726f
commit 6cb9d755d9
Notes: sideshowbarker 2024-07-16 22:34:39 +09:00
3 changed files with 10 additions and 1 deletions

View file

@ -0,0 +1,3 @@
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
BlockContainer <html> at (0,0) content-size 800x16 [BFC] children: not-inline
BlockContainer <body> at (8,8) content-size 784x0 children: not-inline

View file

@ -0,0 +1,3 @@
<!doctype html><style>
body { stroke-width: 5%; }
</style>

View file

@ -10,6 +10,7 @@
#include <LibWeb/CSS/StyleValues/BackgroundSizeStyleValue.h>
#include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h>
#include <LibWeb/CSS/StyleValues/EdgeStyleValue.h>
#include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
#include <LibWeb/CSS/StyleValues/StyleValueList.h>
#include <LibWeb/CSS/StyleValues/URLStyleValue.h>
#include <LibWeb/DOM/Document.h>
@ -665,8 +666,10 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style)
// https://svgwg.org/svg2-draft/coords.html#TermUserUnits
if (stroke_width->is_numeric())
computed_values.set_stroke_width(CSS::Length::make_px(stroke_width->to_number()));
else
else if (stroke_width->is_length())
computed_values.set_stroke_width(stroke_width->to_length());
else if (stroke_width->is_percentage())
computed_values.set_stroke_width(CSS::LengthPercentage { stroke_width->as_percentage().percentage() });
computed_values.set_fill_opacity(computed_style.fill_opacity());
computed_values.set_stroke_opacity(computed_style.stroke_opacity());