mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Serialize attribute nodes as the empty string (#36875)
The existing code asserts that attribute nodes are never serialized. This is wrong, because you can pass an attribute node to `XMLSerializer::serializeToString`. Instead, the spec mandates that these are serialized as empty strings (https://w3c.github.io/DOM-Parsing/#dfn-xml-serialization-algorithm). Testing: Includes a new web platform test Fixes: https://github.com/servo/servo/issues/36872 --------- Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
parent
03abec4148
commit
51b95a6246
3 changed files with 6 additions and 3 deletions
|
@ -302,11 +302,10 @@ pub(crate) fn serialize_html_fragment<S: Serializer>(
|
||||||
serializer.write_processing_instruction(pi.target(), &data)?;
|
serializer.write_processing_instruction(pi.target(), &data)?;
|
||||||
},
|
},
|
||||||
|
|
||||||
NodeTypeId::DocumentFragment(_) => {},
|
NodeTypeId::DocumentFragment(_) | NodeTypeId::Attr => {},
|
||||||
|
|
||||||
NodeTypeId::Document(_) => panic!("Can't serialize Document node itself"),
|
NodeTypeId::Document(_) => panic!("Can't serialize Document node itself"),
|
||||||
NodeTypeId::Element(_) => panic!("Element shouldn't appear here"),
|
NodeTypeId::Element(_) => panic!("Element shouldn't appear here"),
|
||||||
NodeTypeId::Attr => panic!("Attr shouldn't appear here"),
|
|
||||||
},
|
},
|
||||||
SerializationCommand::SerializeShadowRoot(shadow_root) => {
|
SerializationCommand::SerializeShadowRoot(shadow_root) => {
|
||||||
// Shadow roots are serialized as template elements with a fixed set of
|
// Shadow roots are serialized as template elements with a fixed set of
|
||||||
|
|
2
tests/wpt/meta/MANIFEST.json
vendored
2
tests/wpt/meta/MANIFEST.json
vendored
|
@ -627813,7 +627813,7 @@
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
"XMLSerializer-serializeToString.html": [
|
"XMLSerializer-serializeToString.html": [
|
||||||
"6c294e464a5dc787abd4d10281ab2fe0555a0a3c",
|
"352a62c7d5db0710da6819bbc094ebfae46f4099",
|
||||||
[
|
[
|
||||||
null,
|
null,
|
||||||
{}
|
{}
|
||||||
|
|
|
@ -256,6 +256,10 @@ test(function () {
|
||||||
root.setAttributeNS(XMLNS_URI, 'xmlns:foo', '');
|
root.setAttributeNS(XMLNS_URI, 'xmlns:foo', '');
|
||||||
assert_equals(serialize(root), '<root xmlns="" xmlns:foo=""/>');
|
assert_equals(serialize(root), '<root xmlns="" xmlns:foo=""/>');
|
||||||
}, 'Check if a prefix bound to an empty namespace URI ("no namespace") serialize');
|
}, 'Check if a prefix bound to an empty namespace URI ("no namespace") serialize');
|
||||||
|
|
||||||
|
test(function() {
|
||||||
|
assert_equals(serialize(document.createAttribute("foobar")), "")
|
||||||
|
}, 'Attribute nodes are serialized as the empty string')
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue