Skip to content

Truly independent web browser

LibWeb: Share the text of a node's only text child

Shannon Booth3b68e0f728f6
diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp
index f6670e3cbb2..68f026c065e 100644
--- a/Libraries/LibWeb/DOM/Node.cpp
+++ b/Libraries/LibWeb/DOM/Node.cpp
@@ -711,12 +711,16 @@ CSS::StyleScope& Node::style_scope()
return document().style_scope();
}
+// https://dom.spec.whatwg.org/#concept-child-text-content
Utf16String Node::child_text_content() const
{
auto const* parent_node = as_if<ParentNode>(*this);
if (!parent_node)
return {};
+ if (auto const* text = as_if<Text>(parent_node->first_child()); text && !text->next_sibling())
+ return text->data();
+
Utf16StringBuilder builder;
parent_node->for_each_child_of_type<Text>([&](auto const& child) {