From 5deb2b4cad3755c7e9251f6b23e9b1089b029aa7 Mon Sep 17 00:00:00 2001 From: Milo van der Tier Date: Mon, 25 Nov 2024 21:34:29 +0100 Subject: [PATCH] LibWeb: Do not give the HTML namespace to elements when parsing XML While the code that did this referred to the HTML spec, other browsers appear not to have this behavior when parsing XML, and it breaks a WPT subtest. This change does not appear to break any tests, and fixes 1 WPT subtest. --- Libraries/LibWeb/XML/XMLDocumentBuilder.cpp | 14 -- .../XMLSerializer-serializeToString.txt | 35 +++ .../XMLSerializer-serializeToString.html | 237 ++++++++++++++++++ 3 files changed, 272 insertions(+), 14 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/wpt-import/domparsing/XMLSerializer-serializeToString.txt create mode 100644 Tests/LibWeb/Text/input/wpt-import/domparsing/XMLSerializer-serializeToString.html diff --git a/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp b/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp index 3e8b1be02fd4..b8c05f5e6257 100644 --- a/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp +++ b/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp @@ -92,27 +92,13 @@ void XMLDocumentBuilder::element_start(const XML::Name& name, HashMapvalue)); } else { m_namespace_stack.last().depth += 1; } - if (name == HTML::TagNames::html.to_deprecated_fly_string() && m_namespace != Namespace::HTML) { - // HTML / 2.1.3 XML compatibility: https://html.spec.whatwg.org/#xml - // To ease migration from HTML to XML, user agents conforming to this specification will place elements in HTML - // in the http://www.w3.org/1999/xhtml namespace, at least for the purposes of the DOM and CSS. - // The term "HTML elements" refers to any element in that namespace, even in XML documents. - if (found_explicit_namespace || m_namespace_stack.size() != 1 || m_namespace_stack.last().depth != 2) { - m_has_error = true; - return; - } - m_namespace = Namespace::HTML; - } - auto node = DOM::create_element(m_document, MUST(FlyString::from_deprecated_fly_string(name)), m_namespace).release_value_but_fixme_should_propagate_errors(); // When an XML parser with XML scripting support enabled creates a script element, diff --git a/Tests/LibWeb/Text/expected/wpt-import/domparsing/XMLSerializer-serializeToString.txt b/Tests/LibWeb/Text/expected/wpt-import/domparsing/XMLSerializer-serializeToString.txt new file mode 100644 index 000000000000..3c116ea8fc35 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/domparsing/XMLSerializer-serializeToString.txt @@ -0,0 +1,35 @@ +Summary + +Harness status: OK + +Rerun + +Found 24 tests + +8 Pass +16 Fail +Details +Result Test Name MessagePass check XMLSerializer.serializeToString method could parsing xmldoc to string +Pass check XMLSerializer.serializeToString method could parsing document to string +Pass Check if the default namespace is correctly reset. +Pass Check if there is no redundant empty namespace declaration. +Fail Check if redundant xmlns="..." is dropped. +Pass Check if inconsistent xmlns="..." is dropped. +Fail Check if an attribute with namespace and no prefix is serialized with the nearest-declared prefix +Fail Check if an attribute with namespace and no prefix is serialized with the nearest-declared prefix even if the prefix is assigned to another namespace. +Fail Check if the prefix of an attribute is replaced with another existing prefix mapped to the same namespace URI. +Fail Check if the prefix of an attribute is NOT preserved in a case where neither its prefix nor its namespace URI is not already used. +Fail Check if the prefix of an attribute is replaced with a generated one in a case where the prefix is already mapped to a different namespace URI. +Fail check XMLSerializer.serializeToString escapes attribute values for roundtripping +Fail Check if attribute serialization takes into account of following xmlns:* attributes +Fail Check if attribute serialization takes into account of the same prefix declared in an ancestor element +Fail Check if start tag serialization drops element prefix if the namespace is same as inherited default namespace. +Fail Check if start tag serialization finds an appropriate prefix. +Fail Check if start tag serialization takes into account of its xmlns:* attributes +Fail Check if start tag serialization applied the original prefix even if it is declared in an ancestor element. +Fail Check if start tag serialization does NOT apply the default namespace if its namespace is declared in an ancestor. +Pass +Fail Check if "ns1" is generated even if the element already has xmlns:ns1. +Fail Check if no special handling for XLink namespace unlike HTML serializer. +Pass Check if document fragment serializes. +Pass Check children were included for void elements \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/domparsing/XMLSerializer-serializeToString.html b/Tests/LibWeb/Text/input/wpt-import/domparsing/XMLSerializer-serializeToString.html new file mode 100644 index 000000000000..ef23bebe645c --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/domparsing/XMLSerializer-serializeToString.html @@ -0,0 +1,237 @@ + + + + + domparsing Test: XMLSerializer.serializeToString + + + + +

domparsing_XMLSerializer_serializeToString

+ + +