From 6d29afaa6c70025e1214be00f53890a11e8a06a3 Mon Sep 17 00:00:00 2001 From: sideshowbarker Date: Wed, 6 Nov 2024 17:40:55 +0900 Subject: [PATCH] LibWeb: Fix accessible-name computation for aria-labelledby cases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change ensures that when the aria-labelledby attribute is used, the expected text from the element referenced in the aria-labelledby value appears in the computed accessible name. Otherwise, without this change, the expected text doesn’t appear in the computed accessible name. --- Libraries/LibWeb/DOM/Node.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp index c34aff05fbf..ebf2e3d0393 100644 --- a/Libraries/LibWeb/DOM/Node.cpp +++ b/Libraries/LibWeb/DOM/Node.cpp @@ -2227,7 +2227,8 @@ ErrorOr Node::name_or_description(NameOrDescription target, Document con // b. Compute the text alternative of the current node beginning with step 2. Set the result to that text alternative. auto result = TRY(node->name_or_description(target, document, visited_nodes)); // c. Append the result, with a space, to the accumulated text. - TRY(Node::append_with_space(total_accumulated_text, result)); + total_accumulated_text.append(' '); + total_accumulated_text.append(result); } // iii. Return the accumulated text. return total_accumulated_text.to_string(); @@ -2388,7 +2389,8 @@ ErrorOr Node::name_or_description(NameOrDescription target, Document con total_accumulated_text.append(after->computed_values().content().data); } // v. Return the accumulated text if it is not the empty string (""). - return total_accumulated_text.to_string(); + if (!total_accumulated_text.is_empty()) + return total_accumulated_text.to_string(); // Important: Each node in the subtree is consulted only once. If text has been collected from a descendant, but is referenced by another IDREF in some descendant node, then that second, or subsequent, reference is not followed. This is done to avoid infinite loops. } }