diff --git a/Tests/LibWeb/Layout/expected/svg/svg-viewbox-zero-width.txt b/Tests/LibWeb/Layout/expected/svg/svg-viewbox-zero-width.txt new file mode 100644 index 00000000000..9a0e52e9057 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/svg/svg-viewbox-zero-width.txt @@ -0,0 +1,10 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x166 [BFC] children: not-inline + BlockContainer at (8,8) content-size 784x150 children: inline + frag 0 from SVGSVGBox start: 0, length: 0, rect: [8,8 300x150] baseline: 150 + SVGSVGBox at (8,8) content-size 300x150 [SVG] children: not-inline + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x166] + PaintableWithLines (BlockContainer) [8,8 784x150] + SVGSVGPaintable (SVGSVGBox) [8,8 300x150] diff --git a/Tests/LibWeb/Layout/input/svg/svg-viewbox-zero-width.html b/Tests/LibWeb/Layout/input/svg/svg-viewbox-zero-width.html new file mode 100644 index 00000000000..6cea3547fa2 --- /dev/null +++ b/Tests/LibWeb/Layout/input/svg/svg-viewbox-zero-width.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Userland/Libraries/LibWeb/Layout/SVGSVGBox.cpp b/Userland/Libraries/LibWeb/Layout/SVGSVGBox.cpp index a23435fbad3..d25f7ff55b6 100644 --- a/Userland/Libraries/LibWeb/Layout/SVGSVGBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/SVGSVGBox.cpp @@ -75,9 +75,10 @@ Optional SVGSVGBox::calculate_intrinsic_aspect_ratio() const auto const& viewbox = dom_node().view_box().value(); // 2. return viewbox.width / viewbox.height + auto viewbox_width = CSSPixels::nearest_value_for(viewbox.width); auto viewbox_height = CSSPixels::nearest_value_for(viewbox.height); - if (viewbox_height != 0) - return CSSPixels::nearest_value_for(viewbox.width) / viewbox_height; + if (viewbox_width != 0 && viewbox_height != 0) + return viewbox_width / viewbox_height; return {}; }