mirror of
https://github.com/SerenityOS/serenity
synced 2024-07-21 10:05:32 +00:00
LibWeb/XML: Avoid placing all elements missing an ns in the HTML ns
Also remove the hack for SVG documents, a well-formed SVG document has the correct xmlns attribute set, which should be automatically picked up by the builder now.
This commit is contained in:
parent
830f1dbbfe
commit
ebe254a6d3
2
Tests/LibWeb/Text/expected/XML/parser-namespace.txt
Normal file
2
Tests/LibWeb/Text/expected/XML/parser-namespace.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
PASS
|
||||
|
20
Tests/LibWeb/Text/input/XML/parser-namespace.html
Normal file
20
Tests/LibWeb/Text/input/XML/parser-namespace.html
Normal file
|
@ -0,0 +1,20 @@
|
|||
<script src="../include.js"></script>
|
||||
<script>
|
||||
asyncTest((done) => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.responseType = "document";
|
||||
xhr.open("GET", "data:text/xml,<?xml version='1.0'?><random xmlns=\"some.random/namespace\"><inner/></random>", true);
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState !== 4 || xhr.status !== 200)
|
||||
return;
|
||||
let xml = xhr.responseXML;
|
||||
const expected = "some.random/namespace";
|
||||
if (xml.documentElement.namespaceURI == expected && xml.documentElement.childNodes[0].namespaceURI == expected)
|
||||
println("PASS");
|
||||
else
|
||||
println("FAIL");
|
||||
done();
|
||||
};
|
||||
xhr.send();
|
||||
});
|
||||
</script>
|
|
@ -42,6 +42,7 @@ XMLDocumentBuilder::XMLDocumentBuilder(DOM::Document& document, XMLScriptingSupp
|
|||
, m_current_node(m_document)
|
||||
, m_scripting_support(scripting_support)
|
||||
{
|
||||
m_namespace_stack.append({ m_namespace, 1 });
|
||||
}
|
||||
|
||||
void XMLDocumentBuilder::set_source(DeprecatedString source)
|
||||
|
@ -54,21 +55,16 @@ void XMLDocumentBuilder::element_start(const XML::Name& name, HashMap<XML::Name,
|
|||
if (m_has_error)
|
||||
return;
|
||||
|
||||
// FIXME: This should not live here at all.
|
||||
if (auto it = attributes.find("xmlns"); it != attributes.end()) {
|
||||
if (name == HTML::TagNames::html.to_deprecated_fly_string() && it->value != Namespace::HTML) {
|
||||
m_has_error = true;
|
||||
return;
|
||||
}
|
||||
m_namespace_stack.append({ m_namespace, 1 });
|
||||
m_namespace = it->value;
|
||||
} else {
|
||||
m_namespace_stack.last().depth += 1;
|
||||
}
|
||||
|
||||
if (name == HTML::TagNames::svg.to_deprecated_fly_string()) {
|
||||
if (it->value != Namespace::SVG) {
|
||||
m_has_error = true;
|
||||
return;
|
||||
}
|
||||
|
||||
m_namespace = Namespace::SVG;
|
||||
}
|
||||
if (name == HTML::TagNames::html.to_deprecated_fly_string() && m_namespace != Namespace::HTML) {
|
||||
m_has_error = true;
|
||||
return;
|
||||
}
|
||||
|
||||
auto node = DOM::create_element(m_document, MUST(FlyString::from_deprecated_fly_string(name)), m_namespace).release_value_but_fixme_should_propagate_errors();
|
||||
|
@ -98,6 +94,11 @@ void XMLDocumentBuilder::element_end(const XML::Name& name)
|
|||
{
|
||||
if (m_has_error)
|
||||
return;
|
||||
|
||||
if (--m_namespace_stack.last().depth == 0) {
|
||||
m_namespace = m_namespace_stack.take_last().ns;
|
||||
}
|
||||
|
||||
VERIFY(m_current_node->node_name().equals_ignoring_ascii_case(name));
|
||||
// When an XML parser with XML scripting support enabled creates a script element, [...]
|
||||
// When the element's end tag is subsequently parsed,
|
||||
|
|
|
@ -42,7 +42,13 @@ private:
|
|||
XMLScriptingSupport m_scripting_support { XMLScriptingSupport::Enabled };
|
||||
bool m_has_error { false };
|
||||
StringBuilder text_builder;
|
||||
DeprecatedFlyString m_namespace { Namespace::HTML };
|
||||
DeprecatedFlyString m_namespace {};
|
||||
|
||||
struct NamespaceStackEntry {
|
||||
DeprecatedFlyString ns;
|
||||
size_t depth;
|
||||
};
|
||||
Vector<NamespaceStackEntry, 2> m_namespace_stack;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue