Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 56 additions & 12 deletions src/meta/iinf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,11 @@ impl AtomExt for ItemInfoEntry {
(self.item_id as u16).encode(buf)?;
self.item_protection_index.encode(buf)?;
self.item_name.as_str().encode(buf)?;
self.content_type.clone().unwrap().as_str().encode(buf)?;
self.content_encoding
.clone()
.unwrap_or("".to_string())
.as_str()
.encode(buf)?;
let content_type = self.content_type.as_deref().ok_or(Error::MissingContent(
"content_type required for infe version 0",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"content_type required for infe version 0",
"content_type required for infe version 0 or 1",

))?;
content_type.encode(buf)?;
self.content_encoding.as_deref().unwrap_or("").encode(buf)?;
if version == ItemInfoEntryVersion::V1 {
return Err(Error::Unsupported("infe version 1 extensions"));
}
Expand All @@ -85,12 +84,11 @@ impl AtomExt for ItemInfoEntry {
Some(self.item_type).encode(buf)?;
self.item_name.as_str().encode(buf)?;
if self.item_type == Some(FourCC::new(b"mime")) {
self.content_type.clone().unwrap().as_str().encode(buf)?;
self.content_encoding
.clone()
.unwrap_or("".to_string())
.as_str()
.encode(buf)?;
let content_type = self.content_type.as_deref().ok_or(Error::MissingContent(
"content_type required with 'mime' item_type",
))?;
content_type.encode(buf)?;
self.content_encoding.as_deref().unwrap_or("").encode(buf)?;
} else if self.item_type == Some(FourCC::new(b"uri ")) {
let item_uri_type = self.item_uri_type.as_ref().ok_or(Error::MissingContent(
"item_uri_type required with 'uri ' item_type",
Expand Down Expand Up @@ -321,6 +319,52 @@ mod tests {
));
}

/// Rejects a version 0 item info entry when its required content type is missing.
#[test]
fn test_iinf_encode_v0_without_content_type_returns_error() {
let iinf = Iinf {
item_infos: vec![ItemInfoEntry {
item_id: 1,
item_protection_index: 0,
item_type: None,
item_name: "Item".to_string(),
content_type: None,
content_encoding: None,
item_uri_type: None,
item_not_in_presentation: false,
}],
};
let mut buf = Vec::new();

assert!(matches!(
iinf.encode(&mut buf),
Err(Error::MissingContent(_))
));
}

/// Rejects a `mime` item info entry when its required content type is missing.
#[test]
fn test_iinf_encode_mime_without_content_type_returns_error() {
let iinf = Iinf {
item_infos: vec![ItemInfoEntry {
item_id: 1,
item_protection_index: 0,
item_type: Some(FourCC::new(b"mime")),
item_name: "Item".to_string(),
content_type: None,
content_encoding: None,
item_uri_type: None,
item_not_in_presentation: false,
}],
};
let mut buf = Vec::new();

assert!(matches!(
iinf.encode(&mut buf),
Err(Error::MissingContent(_))
));
}

/// Version 1 `infe` entries are reported as unsupported, not panicked.
#[test]
fn test_iinf_decode_unsupported_infe_v1_returns_error() {
Expand Down
Loading