LibWeb/SVG: Parse comma-separated SVG viewBox

From the SVG spec

The value of the ‘viewBox’ attribute is a list of four numbers <min-x>,
<min-y>, <width> and <height>, separated by whitespace and/or a comma...

Currently try_parse_view_box will fail to parse the attribute if the
values are separated by commas.

This change replaces try_parse_view_box with a more correct
implementation. It will reside in the AttributeParser.cpp. This new
implementation correctly handles comma-separated viewBox values, and is
also more robust against invalid inputs.

Additionally, it adds a new test case to ensure viewBox values with
various syntax are parsed correctly and invalid values are rejected.
This commit is contained in:
Erik Kurzinger 2025-08-28 11:03:53 -04:00 committed by Alexander Kalenik
commit 21ff66c6cb
Notes: github-actions[bot] 2025-08-30 13:50:27 +00:00
12 changed files with 104 additions and 91 deletions

View file

@ -28,7 +28,7 @@ void SVGFitToViewBox::attribute_changed(DOM::Element& element, FlyString const&
if (!value.has_value()) {
m_view_box_for_bindings->set_nulled(true);
} else {
m_view_box = try_parse_view_box(value.value_or(String {}));
m_view_box = AttributeParser::parse_viewbox(value.value_or(String {}));
m_view_box_for_bindings->set_nulled(!m_view_box.has_value());
if (m_view_box.has_value()) {
m_view_box_for_bindings->set_base_val(Gfx::DoubleRect { m_view_box->min_x, m_view_box->min_y, m_view_box->width, m_view_box->height });