From 3ff613712132bd3d03f44f27986f7ca5aaea8eb5 Mon Sep 17 00:00:00 2001 From: ronak69 Date: Sun, 13 Oct 2024 17:35:35 +0000 Subject: [PATCH] LibWeb: Insert title as first child on setting title of svg document Before, the new title element got appended instead of prepended, as nullptr was passed as the "child" argument to the insert_before() function. This change makes two WPT tests pass in: http://wpt.live/html/dom/documents/dom-tree-accessors/document.title-09.html --- .../DOM/Document-svg-title-element-first-child.txt | 1 + .../DOM/Document-svg-title-element-first-child.html | 12 ++++++++++++ Userland/Libraries/LibWeb/DOM/Document.cpp | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/expected/DOM/Document-svg-title-element-first-child.txt create mode 100644 Tests/LibWeb/Text/input/DOM/Document-svg-title-element-first-child.html diff --git a/Tests/LibWeb/Text/expected/DOM/Document-svg-title-element-first-child.txt b/Tests/LibWeb/Text/expected/DOM/Document-svg-title-element-first-child.txt new file mode 100644 index 0000000000..e67304570e --- /dev/null +++ b/Tests/LibWeb/Text/expected/DOM/Document-svg-title-element-first-child.txt @@ -0,0 +1 @@ +title == title diff --git a/Tests/LibWeb/Text/input/DOM/Document-svg-title-element-first-child.html b/Tests/LibWeb/Text/input/DOM/Document-svg-title-element-first-child.html new file mode 100644 index 0000000000..af8566e22d --- /dev/null +++ b/Tests/LibWeb/Text/input/DOM/Document-svg-title-element-first-child.html @@ -0,0 +1,12 @@ + + + diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index a673e86571..e19ed7d6b8 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -923,7 +923,7 @@ WebIDL::ExceptionOr Document::set_title(String const& title) element = TRY(DOM::create_element(*this, HTML::TagNames::title, Namespace::SVG)); // 2. Insert element as the first child of the document element. - document_element->insert_before(*element, nullptr); + document_element->insert_before(*element, document_element->first_child()); } // 3. String replace all with the given value within element.