From c8d8640018bc71dfbb07f2de5b82ec2c160ee8e8 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 8 Jun 2023 11:37:08 -0400 Subject: [PATCH] LibWeb: Detect when an XML document belongs in the SVG namespace We currently parse all XML documents as belonging in the HTML namespace. Switch to the SVG namespace when parsing an SVG document. --- .../Libraries/LibWeb/XML/XMLDocumentBuilder.cpp | 16 ++++++++++++---- .../Libraries/LibWeb/XML/XMLDocumentBuilder.h | 2 ++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp b/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp index 3bdaefa156..c80472ad2e 100644 --- a/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp +++ b/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp @@ -14,8 +14,6 @@ inline namespace { extern char const* s_xhtml_unified_dtd; } -static DeprecatedFlyString s_html_namespace = "http://www.w3.org/1999/xhtml"; - namespace Web { ErrorOr resolve_xml_resource(XML::SystemID const&, Optional const& public_id) @@ -58,13 +56,23 @@ void XMLDocumentBuilder::element_start(const XML::Name& name, HashMapvalue != s_html_namespace) { + if (name == HTML::TagNames::html && it->value != Namespace::HTML) { m_has_error = true; return; } + + if (name == HTML::TagNames::svg) { + if (it->value != Namespace::SVG) { + m_has_error = true; + return; + } + + m_namespace = Namespace::SVG; + } } - auto node = DOM::create_element(m_document, name, s_html_namespace).release_value_but_fixme_should_propagate_errors(); + auto node = DOM::create_element(m_document, name, m_namespace).release_value_but_fixme_should_propagate_errors(); + // When an XML parser with XML scripting support enabled creates a script element, // it must have its parser document set and its "force async" flag must be unset. // FIXME: If the parser was created as part of the XML fragment parsing algorithm, then the element must be marked as "already started" also. diff --git a/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.h b/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.h index 286f298e77..7f31afa625 100644 --- a/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.h +++ b/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.h @@ -11,6 +11,7 @@ #include #include #include +#include #include namespace Web { @@ -41,6 +42,7 @@ private: XMLScriptingSupport m_scripting_support { XMLScriptingSupport::Enabled }; bool m_has_error { false }; StringBuilder text_builder; + DeprecatedFlyString m_namespace { Namespace::HTML }; }; }