mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 09:45:06 +02:00
LibWeb: Serialize HTML attribute names as per spec
This commit is contained in:
committed by
Jelle Raaijmakers
parent
4772e1b0c9
commit
47796e7967
Notes:
github-actions[bot]
2025-09-15 08:09:19 +00:00
Author: https://github.com/lpas 🔰 Commit: https://github.com/LadybirdBrowser/ladybird/commit/47796e79674 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6187 Reviewed-by: https://github.com/gmta ✅
@@ -5205,22 +5205,39 @@ String HTMLParser::serialize_html_fragment(DOM::Node const& node, SerializableSh
|
||||
builder.append(' ');
|
||||
|
||||
// An attribute's serialized name for the purposes of the previous paragraph must be determined as follows:
|
||||
|
||||
// NOTE: As far as I can tell, these steps are equivalent to just using the qualified name.
|
||||
//
|
||||
// -> If the attribute has no namespace:
|
||||
// The attribute's serialized name is the attribute's local name.
|
||||
if (!attribute.namespace_uri().has_value()) {
|
||||
// The attribute's serialized name is the attribute's local name.
|
||||
builder.append(attribute.local_name());
|
||||
}
|
||||
// -> If the attribute is in the XML namespace:
|
||||
// The attribute's serialized name is the string "xml:" followed by the attribute's local name.
|
||||
else if (attribute.namespace_uri() == Namespace::XML) {
|
||||
// The attribute's serialized name is the string "xml:" followed by the attribute's local name.
|
||||
builder.append("xml:"sv);
|
||||
builder.append(attribute.local_name());
|
||||
}
|
||||
// -> If the attribute is in the XMLNS namespace and the attribute's local name is xmlns:
|
||||
// The attribute's serialized name is the string "xmlns".
|
||||
else if (attribute.namespace_uri() == Namespace::XMLNS && attribute.local_name() == "xmlns") {
|
||||
// The attribute's serialized name is the string "xmlns".
|
||||
builder.append("xmlns"sv);
|
||||
}
|
||||
// -> If the attribute is in the XMLNS namespace and the attribute's local name is not xmlns:
|
||||
// The attribute's serialized name is the string "xmlns:" followed by the attribute's local name.
|
||||
else if (attribute.namespace_uri() == Namespace::XMLNS) {
|
||||
// The attribute's serialized name is the string "xmlns:" followed by the attribute's local name.
|
||||
builder.append("xmlns:"sv);
|
||||
builder.append(attribute.local_name());
|
||||
}
|
||||
// -> If the attribute is in the XLink namespace:
|
||||
// The attribute's serialized name is the string "xlink:" followed by the attribute's local name.
|
||||
else if (attribute.namespace_uri() == Namespace::XLink) {
|
||||
// The attribute's serialized name is the string "xlink:" followed by the attribute's local name.
|
||||
builder.append("xlink:"sv);
|
||||
builder.append(attribute.local_name());
|
||||
}
|
||||
// -> If the attribute is in some other namespace:
|
||||
// The attribute's serialized name is the attribute's qualified name.
|
||||
builder.append(attribute.name());
|
||||
else {
|
||||
// The attribute's serialized name is the attribute's qualified name.
|
||||
builder.append(attribute.name());
|
||||
}
|
||||
|
||||
builder.append("=\""sv);
|
||||
builder.append(escape_string(attribute.value().code_points(), AttributeMode::Yes));
|
||||
|
||||
Reference in New Issue
Block a user