mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-07 08:39:22 +00:00
LibWeb: Update DOMImplementation.createDocumentType()
name validation
This now follows the latest specification steps.
This commit is contained in:
parent
f98312d022
commit
16dbb44de2
Notes:
github-actions[bot]
2025-06-19 11:57:08 +00:00
Author: https://github.com/tcl3
Commit: 16dbb44de2
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5141
Reviewed-by: https://github.com/gmta ✅
Reviewed-by: https://github.com/trflynn89 ✅
6 changed files with 228 additions and 6 deletions
|
@ -137,14 +137,16 @@ GC::Ref<Document> DOMImplementation::create_html_document(Optional<String> const
|
|||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-domimplementation-createdocumenttype
|
||||
WebIDL::ExceptionOr<GC::Ref<DocumentType>> DOMImplementation::create_document_type(String const& qualified_name, String const& public_id, String const& system_id)
|
||||
WebIDL::ExceptionOr<GC::Ref<DocumentType>> DOMImplementation::create_document_type(String const& name, String const& public_id, String const& system_id)
|
||||
{
|
||||
// 1. Validate qualifiedName.
|
||||
TRY(Document::validate_qualified_name(realm(), qualified_name));
|
||||
|
||||
// 2. Return a new doctype, with qualifiedName as its name, publicId as its public ID, and systemId as its system ID, and with its node document set to the associated document of this.
|
||||
// 1. If name is not a valid doctype name, then throw an "InvalidCharacterError" DOMException.
|
||||
if (!is_valid_doctype_name(name))
|
||||
return WebIDL::InvalidCharacterError::create(realm(), "Invalid doctype name"_string);
|
||||
|
||||
// 2. Return a new doctype, with name as its name, publicId as its public ID, and systemId as its system ID, and with its node document set to the associated document of this.
|
||||
auto document_type = DocumentType::create(document());
|
||||
document_type->set_name(qualified_name);
|
||||
document_type->set_name(name);
|
||||
document_type->set_public_id(public_id);
|
||||
document_type->set_system_id(system_id);
|
||||
return document_type;
|
||||
|
|
|
@ -23,7 +23,7 @@ public:
|
|||
|
||||
WebIDL::ExceptionOr<GC::Ref<XMLDocument>> create_document(Optional<FlyString> const&, String const&, GC::Ptr<DocumentType>) const;
|
||||
GC::Ref<Document> create_html_document(Optional<String> const& title) const;
|
||||
WebIDL::ExceptionOr<GC::Ref<DocumentType>> create_document_type(String const& qualified_name, String const& public_id, String const& system_id);
|
||||
WebIDL::ExceptionOr<GC::Ref<DocumentType>> create_document_type(String const& name, String const& public_id, String const& system_id);
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-domimplementation-hasfeature
|
||||
bool has_feature() const
|
||||
|
|
|
@ -28,4 +28,12 @@ void DocumentType::initialize(JS::Realm& realm)
|
|||
Base::initialize(realm);
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#valid-doctype-name
|
||||
bool is_valid_doctype_name(String const& name)
|
||||
{
|
||||
// A string is a valid doctype name if it does not contain ASCII whitespace, U+0000 NULL, or U+003E (>).
|
||||
constexpr Array<u32, 7> INVALID_DOCTYPE_CHARACTERS { '\t', '\n', '\f', '\r', ' ', '\0', '>' };
|
||||
return !name.code_points().contains_any_of(INVALID_DOCTYPE_CHARACTERS);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -44,6 +44,8 @@ private:
|
|||
String m_system_id;
|
||||
};
|
||||
|
||||
bool is_valid_doctype_name(String const&);
|
||||
|
||||
template<>
|
||||
inline bool Node::fast_is<DocumentType>() const { return is_document_type(); }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue