diff --git a/lofty/src/util/text.rs b/lofty/src/util/text.rs index f1fd7e201..f7be94ebe 100644 --- a/lofty/src/util/text.rs +++ b/lofty/src/util/text.rs @@ -75,6 +75,12 @@ const EMPTY_DECODED_TEXT: DecodeTextResult = DecodeTextResult { bom: [0, 0], }; +const EMPTY_DECODED_TEXT_TERMINATED: DecodeTextResult = DecodeTextResult { + content: String::new(), + bytes_read: 1, + bom: [0, 0], +}; + /// Specify how to decode the provided text /// /// By default, this will: @@ -131,7 +137,7 @@ where let (bytes, terminator_len) = read_to_terminator(reader, options.encoding); if bytes.is_empty() { - return Ok(EMPTY_DECODED_TEXT); + return Ok(EMPTY_DECODED_TEXT_TERMINATED); } bytes_read = bytes.len() + terminator_len; @@ -402,6 +408,19 @@ mod tests { ) .unwrap(); + let empty_text_fragment = super::decode_text( + &mut Cursor::new(&[ + 0x00, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x02, + ]), + TextDecodeOptions::new() + .encoding(TextEncoding::UTF8) + .terminated(true), + ) + .unwrap(); + assert_eq!(empty_text_fragment.content, ""); + assert_eq!(empty_text_fragment.bytes_read, 1); + assert_eq!(utf8_decode.content, TEST_STRING.to_string()); }