LibWeb/SVG: Ignore view boxes with negative width or height

This commit is contained in:
Tim Ledbetter 2025-07-12 14:35:48 +01:00 committed by Andreas Kling
commit d38fac7518
Notes: github-actions[bot] 2025-07-21 22:53:29 +00:00
4 changed files with 17 additions and 0 deletions

View file

@ -41,9 +41,13 @@ Optional<ViewBox> try_parse_view_box(StringView string)
view_box.min_y = maybe_number.value();
break;
case State::Width:
if (*maybe_number < 0)
return {};
view_box.width = maybe_number.value();
break;
case State::Height:
if (*maybe_number < 0)
return {};
view_box.height = maybe_number.value();
break;
default:

View file

@ -0,0 +1,2 @@
<!DOCTYPE html>
<div style="width: 100px; height: 100px; background-color: green"></div>

View file

@ -0,0 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" width="100" viewBox="0 0 100 100">
<view id="transform" viewBox="-100 -100 200 200"/>
<view id="invalid" viewBox="0 0 -100 200"/>
<rect width="100" height="100" fill="green"/>
</svg>

After

Width:  |  Height:  |  Size: 229 B

View file

@ -0,0 +1,6 @@
<!doctype HTML>
<title>view element with invalid viewBox should be ignored</title>
<link rel="help" href="https://svgwg.org/svg2-draft/linking.html#ViewElement">
<link rel="match" href="../../../../expected/wpt-import/svg/coordinate-systems/../struct/reftests/reference/green-100x100.html">
<img src="support/views.svg#invalid">