1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 06:38:10 +00:00

LibWeb: Check for valid names in Document.createElement() & friends

We now validate that the provided tag names are valid XML tag names,
and otherwise throw an "invalid character" DOM exception.

2% progression on ACID3. :^)
This commit is contained in:
Andreas Kling 2022-02-26 10:00:49 +01:00
parent 8daf603f46
commit fe67fe3791
7 changed files with 82 additions and 24 deletions

View file

@ -20,7 +20,7 @@ DOMImplementation::DOMImplementation(Document& document)
}
// https://dom.spec.whatwg.org/#dom-domimplementation-createdocument
NonnullRefPtr<Document> DOMImplementation::create_document(const String& namespace_, const String& qualified_name) const
ExceptionOr<NonnullRefPtr<Document>> DOMImplementation::create_document(const String& namespace_, const String& qualified_name) const
{
// FIXME: This should specifically be an XML document.
auto xml_document = Document::create();
@ -29,8 +29,12 @@ NonnullRefPtr<Document> DOMImplementation::create_document(const String& namespa
RefPtr<Element> element;
if (!qualified_name.is_empty())
element = xml_document->create_element_ns(namespace_, qualified_name /* FIXME: and an empty dictionary */);
if (!qualified_name.is_empty()) {
auto new_element = xml_document->create_element_ns(namespace_, qualified_name /* FIXME: and an empty dictionary */);
if (new_element.is_exception())
return new_element.exception();
element = new_element.release_value();
}
// FIXME: If doctype is non-null, append doctype to document.