LibWeb: Ignore zero width when calculating SVG intrinsic aspect ratio

Previously, an SVG with width of zero would have am intrinsic aspect
ratio of zero. With this change, if an SVG has a width or height of
zero, the intrinsic aspect ratio is determined by the SVG's viewbox.
This commit is contained in:
Tim Ledbetter 2025-07-21 04:47:55 +01:00 committed by Jelle Raaijmakers
commit 1263d58689
Notes: github-actions[bot] 2025-07-21 09:30:46 +00:00
2 changed files with 3 additions and 4 deletions

View file

@ -172,10 +172,7 @@ Optional<CSSPixelFraction> SVGDecodedImageData::intrinsic_aspect_ratio() const
// https://www.w3.org/TR/SVG2/coords.html#SizingSVGInCSS
auto width = intrinsic_width();
auto height = intrinsic_height();
if (height.has_value() && *height == 0)
return {};
if (width.has_value() && height.has_value())
if (width.has_value() && height.has_value() && *width > 0 && *height > 0)
return *width / *height;
if (auto const& viewbox = m_root_element->view_box(); viewbox.has_value()) {

View file

@ -0,0 +1,2 @@
<!DOCTYPE html>
<img src="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='0' height='1'></svg>">