@@ -755,19 +755,27 @@ mod tests {
755755 use crate :: tag:: utils:: test_utils;
756756 use crate :: tag:: utils:: test_utils:: read_path;
757757 use crate :: {
758- Accessor as _, AudioFile , ItemKey , ItemValue , ParseOptions , SplitTag as _, Tag ,
759- TagExt as _, TagItem , TagType ,
758+ Accessor as _, AudioFile , ItemKey , ItemValue , ParseOptions , ParsingMode , SplitTag as _,
759+ Tag , TagExt as _, TagItem , TagType ,
760760 } ;
761761 use std:: io:: { Cursor , Read as _, Seek as _, Write as _} ;
762762
763- fn read_ilst ( path : & str ) -> Ilst {
764- let tag = crate :: tag :: utils :: test_utils :: read_path ( path) ;
763+ fn read_ilst ( path : & str , parse_mode : ParsingMode ) -> Ilst {
764+ let tag = std :: fs :: read ( path) . unwrap ( ) ;
765765 let len = tag. len ( ) ;
766766
767767 let cursor = Cursor :: new ( tag) ;
768- let mut reader = AtomReader :: new ( cursor, crate :: ParsingMode :: Strict ) . unwrap ( ) ;
768+ let mut reader = AtomReader :: new ( cursor, parse_mode) . unwrap ( ) ;
769+
770+ super :: read:: parse_ilst ( & mut reader, parse_mode, len as u64 ) . unwrap ( )
771+ }
769772
770- super :: read:: parse_ilst ( & mut reader, crate :: ParsingMode :: Strict , len as u64 ) . unwrap ( )
773+ fn read_ilst_strict ( path : & str ) -> Ilst {
774+ read_ilst ( path, ParsingMode :: Strict )
775+ }
776+
777+ fn read_ilst_bestattempt ( path : & str ) -> Ilst {
778+ read_ilst ( path, ParsingMode :: BestAttempt )
771779 }
772780
773781 fn verify_atom ( ilst : & Ilst , ident : [ u8 ; 4 ] , data : & AtomData ) {
@@ -843,7 +851,7 @@ mod tests {
843851
844852 #[ test]
845853 fn ilst_re_read ( ) {
846- let parsed_tag = read_ilst ( "tests/tags/assets/ilst/test.ilst" ) ;
854+ let parsed_tag = read_ilst_strict ( "tests/tags/assets/ilst/test.ilst" ) ;
847855
848856 let mut writer = Vec :: new ( ) ;
849857 parsed_tag. dump_to ( & mut writer) . unwrap ( ) ;
@@ -935,7 +943,7 @@ mod tests {
935943
936944 #[ test]
937945 fn issue_34 ( ) {
938- let ilst = read_ilst ( "tests/tags/assets/ilst/issue_34.ilst" ) ;
946+ let ilst = read_ilst_strict ( "tests/tags/assets/ilst/issue_34.ilst" ) ;
939947
940948 verify_atom (
941949 & ilst,
@@ -954,7 +962,7 @@ mod tests {
954962
955963 #[ test]
956964 fn advisory_rating ( ) {
957- let ilst = read_ilst ( "tests/tags/assets/ilst/advisory_rating.ilst" ) ;
965+ let ilst = read_ilst_strict ( "tests/tags/assets/ilst/advisory_rating.ilst" ) ;
958966
959967 verify_atom (
960968 & ilst,
@@ -1073,7 +1081,7 @@ mod tests {
10731081
10741082 #[ test]
10751083 fn multi_value_atom ( ) {
1076- let ilst = read_ilst ( "tests/tags/assets/ilst/multi_value_atom.ilst" ) ;
1084+ let ilst = read_ilst_strict ( "tests/tags/assets/ilst/multi_value_atom.ilst" ) ;
10771085 let artist_atom = ilst. get ( & AtomIdent :: Fourcc ( * b"\xa9 ART" ) ) . unwrap ( ) ;
10781086
10791087 assert_eq ! (
@@ -1184,7 +1192,7 @@ mod tests {
11841192
11851193 #[ test]
11861194 fn invalid_atom_type ( ) {
1187- let ilst = read_ilst ( "tests/tags/assets/ilst/invalid_atom_type.ilst" ) ;
1195+ let ilst = read_ilst_strict ( "tests/tags/assets/ilst/invalid_atom_type.ilst" ) ;
11881196
11891197 // The tag contains 3 items, however the last one has an invalid type. We will stop at that point, but retain the
11901198 // first two items.
@@ -1195,4 +1203,19 @@ mod tests {
11951203 assert_eq ! ( ilst. disk( ) . unwrap( ) , 1 ) ;
11961204 assert_eq ! ( ilst. disk_total( ) . unwrap( ) , 2 ) ;
11971205 }
1206+
1207+ #[ test]
1208+ fn invalid_string_encoding ( ) {
1209+ let ilst = read_ilst_bestattempt ( "tests/tags/assets/ilst/invalid_string_encoding.ilst" ) ;
1210+
1211+ // The tag has an album string with some unknown encoding, but the rest of the tag
1212+ // is valid. We should have all items present except the album.
1213+ assert_eq ! ( ilst. len( ) , 3 ) ;
1214+
1215+ assert_eq ! ( ilst. artist( ) . unwrap( ) , "Foo artist" ) ;
1216+ assert_eq ! ( ilst. title( ) . unwrap( ) , "Bar title" ) ;
1217+ assert_eq ! ( ilst. comment( ) . unwrap( ) , "Baz comment" ) ;
1218+
1219+ assert ! ( ilst. album( ) . is_none( ) ) ;
1220+ }
11981221}
0 commit comments