Skip to content

Truly independent web browser

LibWeb: Keep an element's own prefix declarations in XMLSerializer

Shannon Booth65a5ff178a13
diff --git a/Libraries/LibWeb/HTML/XMLSerializer.cpp b/Libraries/LibWeb/HTML/XMLSerializer.cpp
index 833c6e9563a..72d4dbb0b4c 100644
--- a/Libraries/LibWeb/HTML/XMLSerializer.cpp
+++ b/Libraries/LibWeb/HTML/XMLSerializer.cpp
@@ -407,20 +407,16 @@ static WebIDL::ExceptionOr<Utf16String> serialize_element_attributes(DOM::Elemen
// - the attr's prefix is not null and either
if (attribute->prefix().has_value()) {
// - the attr's localName is not a key contained in the local prefixes map, or
+ // - the attr's localName is present in the local prefixes map but the value of the key does not match attr's value
auto name_in_local_prefix_map_iterator = local_prefixes_map.find(attribute->local_name());
- if (name_in_local_prefix_map_iterator == local_prefixes_map.end())
- continue;
+ auto is_not_local_prefix_definition = name_in_local_prefix_map_iterator == local_prefixes_map.end() || name_in_local_prefix_map_iterator->value != attribute_value_namespace;
- // - the attr's localName is present in the local prefixes map but the value of the key does not match attr's value
- if (name_in_local_prefix_map_iterator->value != attribute_value_namespace)
+ // and furthermore that the attr's localName (as the prefix to find) is found in the namespace prefix map given the namespace consisting of the attr's value
+ // (the current namespace prefix definition was exactly defined previously--on an ancestor element not the current element whose attributes are being processed).
+ if (is_not_local_prefix_definition && prefix_is_in_prefix_map(attribute->local_name(), namespace_prefix_map, attribute_value_namespace))
continue;
}
- // and furthermore that the attr's localName (as the prefix to find) is found in the namespace prefix map given the namespace consisting of the attr's value
- // (the current namespace prefix definition was exactly defined previously--on an ancestor element not the current element whose attributes are being processed).
- if (prefix_is_in_prefix_map(attribute->local_name(), namespace_prefix_map, attribute_value_namespace))
- continue;
-
// 2. If the require well-formed flag is set (its value is true), and the value of attr's value attribute matches the XMLNS namespace,
// then throw an exception; the serialization of this attribute would produce invalid XML because the XMLNS namespace is reserved and cannot be applied as an element's namespace via XML parsing.
if (require_well_formed == RequireWellFormed::Yes && attribute->value() == Namespace::XMLNS)
diff --git a/Tests/LibWeb/Text/expected/wpt-import/domparsing/XMLSerializer-serializeToString.txt b/Tests/LibWeb/Text/expected/wpt-import/domparsing/XMLSerializer-serializeToString.txt
index a09b3a5f3aa..bb291e8dc19 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/domparsing/XMLSerializer-serializeToString.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/domparsing/XMLSerializer-serializeToString.txt
@@ -2,8 +2,8 @@ Harness status: OK
Found 27 tests
-10 Pass
-17 Fail
+20 Pass
+7 Fail
Pass check XMLSerializer.serializeToString method could parsing xmldoc to string
Pass check XMLSerializer.serializeToString method could parsing document to string
Pass Check if the default namespace is correctly reset.
@@ -14,18 +14,18 @@ Fail Drop inconsistent xmlns="..." by matching on local name
Fail Check if an attribute with namespace and no prefix is serialized with the nearest-declared prefix
Fail Check if an attribute with namespace and no prefix is serialized with the nearest-declared prefix even if the prefix is assigned to another namespace.
Fail Check if the prefix of an attribute is replaced with another existing prefix mapped to the same namespace URI.
-Fail Check if the prefix of an attribute is NOT preserved in a case where neither its prefix nor its namespace URI is not already used.
-Fail Check if the prefix of an attribute is replaced with a generated one in a case where the prefix is already mapped to a different namespace URI.
+Pass Check if the prefix of an attribute is NOT preserved in a case where neither its prefix nor its namespace URI is not already used.
+Pass Check if the prefix of an attribute is replaced with a generated one in a case where the prefix is already mapped to a different namespace URI.
Fail check XMLSerializer.serializeToString escapes attribute values for roundtripping
-Fail Check if attribute serialization takes into account of following xmlns:* attributes
-Fail Check if attribute serialization takes into account of the same prefix declared in an ancestor element
-Fail Check if start tag serialization drops element prefix if the namespace is same as inherited default namespace.
-Fail Check if start tag serialization finds an appropriate prefix.
-Fail Check if start tag serialization takes into account of its xmlns:* attributes
-Fail Check if start tag serialization applied the original prefix even if it is declared in an ancestor element.
-Fail Check if start tag serialization does NOT apply the default namespace if its namespace is declared in an ancestor.
+Pass Check if attribute serialization takes into account of following xmlns:* attributes
+Pass Check if attribute serialization takes into account of the same prefix declared in an ancestor element
+Pass Check if start tag serialization drops element prefix if the namespace is same as inherited default namespace.
+Pass Check if start tag serialization finds an appropriate prefix.
+Pass Check if start tag serialization takes into account of its xmlns:* attributes
+Pass Check if start tag serialization applied the original prefix even if it is declared in an ancestor element.
+Pass Check if start tag serialization does NOT apply the default namespace if its namespace is declared in an ancestor.
Pass Check if generated prefixes match to "ns${index}".
-Fail Check if "ns1" is generated even if the element already has xmlns:ns1.
+Pass Check if "ns1" is generated even if the element already has xmlns:ns1.
Fail Check if no special handling for XLink namespace unlike HTML serializer.
Pass Check if document fragment serializes.
Pass Check children were included for void elements