Skip to content

Truly independent web browser

LibWeb: Don’t recurse into an SVG landmark role’s accessible name

sideshowbarker3d1ae882029d
diff --git a/Libraries/LibWeb/SVG/SVGElement.cpp b/Libraries/LibWeb/SVG/SVGElement.cpp
index 48ce48b2485..39e58b06015 100644
--- a/Libraries/LibWeb/SVG/SVGElement.cpp
+++ b/Libraries/LibWeb/SVG/SVGElement.cpp
@@ -384,7 +384,10 @@ void SVGElement::publish_presentation_attribute_style()
bool SVGElement::should_include_in_accessibility_tree() const
{
bool has_title_or_desc = false;
- auto role = role_from_role_attribute_value();
+ // Whether the element has a role token decides inclusion, so the name-dependent landmark check doesn't apply
+ // here. It computes the accessible name, and computing that asks for this element's default role, which depends
+ // on this check — so applying it here would recurse until the stack overflows.
+ auto role = role_from_role_value(this->role(), RoleSource::DefaultSemantics);
for_each_child_of_type<SVGElement>([&has_title_or_desc](auto& child) {
if ((is<SVGTitleElement>(child) || is<SVGDescElement>(child)) && !child.text_content()->utf16_view().trim_ascii_whitespace().is_empty()) {
has_title_or_desc = true;
diff --git a/Tests/LibWeb/Text/expected/accessibility-tree-svg-landmark-roles.txt b/Tests/LibWeb/Text/expected/accessibility-tree-svg-landmark-roles.txt
new file mode 100644
index 00000000000..05a04873632
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/accessibility-tree-svg-landmark-roles.txt
@@ -0,0 +1,11 @@
+document
+ generic
+ generic
+ generic
+ generic
+ region "Named region"
+ generic
+ generic
+ generic
+ generic
+ generic
diff --git a/Tests/LibWeb/Text/input/accessibility-tree-svg-landmark-roles.html b/Tests/LibWeb/Text/input/accessibility-tree-svg-landmark-roles.html
new file mode 100644
index 00000000000..f4b430f431c
--- /dev/null
+++ b/Tests/LibWeb/Text/input/accessibility-tree-svg-landmark-roles.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<script src="include.js"></script>
+<svg width="100" height="100">
+ <g role="region"><circle cx="20" cy="20" r="10"/></g>
+ <g role="region" aria-label="Named region"><circle cx="50" cy="50" r="10"/></g>
+ <g role="form"><circle cx="80" cy="80" r="10"/></g>
+ <circle role="region" cx="20" cy="80" r="10"/>
+</svg>
+<script>
+ test(() => {
+ const dump = (node, depth) => {
+ const name = node.name ? ` "${node.name}"` : "";
+ println(`${" ".repeat(depth)}${node.role || "(no role)"}${name}`);
+ for (const child of node.children ?? [])
+ dump(child, depth + 1);
+ };
+ dump(JSON.parse(internals.dumpAccessibilityTree()), 0);
+ });
+</script>