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!
This commit is contained in:
Wez Furlong 2024-05-22 10:45:34 -07:00 committed by Dirkjan Ochtman
parent 05de91af02
commit 3e72aa7ae3
2 changed files with 31 additions and 1 deletions

View File

@ -228,7 +228,6 @@ fn serialize_struct(
) -> Result<(), instant_xml::Error> { ) -> Result<(), instant_xml::Error> {
// Start tag // Start tag
let prefix = serializer.write_start(#tag, #default_namespace)?; let prefix = serializer.write_start(#tag, #default_namespace)?;
debug_assert_eq!(prefix, None);
// Set up element context, this will also emit namespace declarations // Set up element context, this will also emit namespace declarations
#context #context

View File

@ -47,3 +47,34 @@ fn struct_child_namespaces() {
"<StructChildNamespaces xmlns=\"URI\" xmlns:bar=\"BAZ\" xmlns:foo=\"BAR\"><NestedDifferentNamespace xmlns=\"\" xmlns:internal=\"INTERNAL\"><internal:flag_internal_prefix>false</internal:flag_internal_prefix></NestedDifferentNamespace><Nested xmlns:internal=\"INTERNAL\"><bar:flag_parent_prefix>true</bar:flag_parent_prefix><internal:flag_internal_prefix>false</internal:flag_internal_prefix></Nested></StructChildNamespaces>" "<StructChildNamespaces xmlns=\"URI\" xmlns:bar=\"BAZ\" xmlns:foo=\"BAR\"><NestedDifferentNamespace xmlns=\"\" xmlns:internal=\"INTERNAL\"><internal:flag_internal_prefix>false</internal:flag_internal_prefix></NestedDifferentNamespace><Nested xmlns:internal=\"INTERNAL\"><bar:flag_parent_prefix>true</bar:flag_parent_prefix><internal:flag_internal_prefix>false</internal:flag_internal_prefix></Nested></StructChildNamespaces>"
); );
} }
#[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<AlbumArtUri>,
}
#[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(), "<DIDL-Lite xmlns=\"DIDL\" xmlns:upnp=\"UPNP\"><item><upnp:albumArtURI>http://art</upnp:albumArtURI></item></DIDL-Lite>");
}