Dump Attribute to empty string

This is normally not called in "normal" dump-usage, but with
XMLSerializer.serializeToString an Attr node _can_ be provided. The spec says,
and FF agrees, this should return an empty string.
This commit is contained in:
Karl Seguin
2026-02-25 18:16:13 +08:00
parent 8f179becf7
commit 25298a32fa
2 changed files with 16 additions and 1 deletions

View File

@@ -172,7 +172,11 @@ fn _deep(node: *Node, opts: Opts, comptime force_slot: bool, writer: *std.Io.Wri
try writer.writeAll(">\n"); try writer.writeAll(">\n");
}, },
.document_fragment => try children(node, opts, writer, page), .document_fragment => try children(node, opts, writer, page),
.attribute => unreachable, .attribute => {
// Not called normally, but can be called via XMLSerializer.serializeToString
// in which case it should return an empty string
try writer.writeAll("");
},
} }
} }

View File

@@ -129,3 +129,14 @@
testing.expectEqual(original, serialized); testing.expectEqual(original, serialized);
} }
</script> </script>
<script id=serializeAttribute>
{
const div = document.createElement('div');
div.setAttribute('over', '9000');
const serializer = new XMLSerializer();
const serialized = serializer.serializeToString(div.getAttributeNode('over'));
testing.expectEqual('', serialized);
}
</script>