From 903531e07f8cbfd2d06d64c07f6541d4e0438872 Mon Sep 17 00:00:00 2001 From: Serial <69764315+Serial-ATA@users.noreply.github.com> Date: Sun, 17 Jul 2022 13:58:27 -0400 Subject: [PATCH] Tag: Add missing return --- CHANGELOG.md | 3 +++ src/tag/mod.rs | 14 +++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29b2750d..27e34964 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)! diff --git a/src/tag/mod.rs b/src/tag/mod.rs index eaba1191..9a26e472 100644 --- a/src/tag/mod.rs +++ b/src/tag/mod.rs @@ -28,6 +28,7 @@ macro_rules! impl_accessor { fn [](&mut self, value: String) { if value.is_empty() { self.[](); + 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); + } }