From 3e72aa7ae3c26dd799e7a0921abedef067b4d98b Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Wed, 22 May 2024 10:45:34 -0700 Subject: [PATCH] fix erroneous debug assertion in nested namespace case The assertion was checking to ensure that the emitted tag had no prefix, which breaks the case where a prefix is required, but only in debug builds! --- instant-xml-macros/src/ser.rs | 1 - instant-xml/tests/ser-child-ns.rs | 31 +++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/instant-xml-macros/src/ser.rs b/instant-xml-macros/src/ser.rs index a4457dd..cb3a803 100644 --- a/instant-xml-macros/src/ser.rs +++ b/instant-xml-macros/src/ser.rs @@ -228,7 +228,6 @@ fn serialize_struct( ) -> Result<(), instant_xml::Error> { // Start tag let prefix = serializer.write_start(#tag, #default_namespace)?; - debug_assert_eq!(prefix, None); // Set up element context, this will also emit namespace declarations #context diff --git a/instant-xml/tests/ser-child-ns.rs b/instant-xml/tests/ser-child-ns.rs index 3162b2b..afcc97b 100644 --- a/instant-xml/tests/ser-child-ns.rs +++ b/instant-xml/tests/ser-child-ns.rs @@ -47,3 +47,34 @@ fn struct_child_namespaces() { "falsetruefalse" ); } + +#[derive(Debug, ToXml)] +#[xml(rename = "DIDL-Lite", ns("DIDL", upnp = "UPNP"))] +pub struct DidlLite { + pub item: UpnpItem, +} + +#[derive(Debug, ToXml)] +#[xml(rename = "item", ns("DIDL"))] +pub struct UpnpItem { + pub album_art: Option, +} + +#[derive(Debug, ToXml)] +#[xml(rename = "albumArtURI", ns("UPNP", upnp = "UPNP"))] +pub struct AlbumArtUri { + #[xml(direct)] + pub uri: String, +} + +#[test] +fn test_didl() { + let didl = DidlLite { + item: UpnpItem { + album_art: Some(AlbumArtUri { + uri: "http://art".to_string(), + }), + }, + }; + assert_eq!(to_string(&didl).unwrap(), "http://art"); +}