Tag: Add missing return

This commit is contained in:
Serial 2022-07-17 13:58:27 -04:00
parent 5d6801b0db
commit 903531e07f
No known key found for this signature in database
GPG key ID: DA95198DC17C4568
2 changed files with 16 additions and 1 deletions

View file

@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Fixed
- **Tag**: The `Accessor::set_*` methods will stop falling through, and adding empty strings
## [0.7.2] - 2022-07-13
This release mostly addresses issues uncovered by fuzzing, thanks to [@5225225](https://github.com/5225225)!

View file

@ -28,6 +28,7 @@ macro_rules! impl_accessor {
fn [<set_ $name>](&mut self, value: String) {
if value.is_empty() {
self.[<remove_ $name>]();
return;
}
self.insert_item(TagItem::new(ItemKey::$item_key, ItemValue::Text(value)));
@ -632,7 +633,7 @@ impl TagType {
#[cfg(test)]
mod tests {
use crate::tag::utils::test_utils::read_path;
use crate::{Picture, PictureType, Tag, TagExt, TagType};
use crate::{Accessor, Picture, PictureType, Tag, TagExt, TagType};
use std::io::{Seek, Write};
use std::process::Command;
@ -666,4 +667,15 @@ mod tests {
!stderr.contains("Header processing failed: Invalid data found when processing input")
);
}
#[test]
fn insert_empty() {
let mut tag = Tag::new(TagType::ID3v2);
tag.set_title(String::from("Foo title"));
assert_eq!(tag.title(), Some("Foo title"));
tag.set_title(String::new());
assert_eq!(tag.title(), None);
}
}