@@ -206,22 +206,21 @@ pub fn parse_vcard(vcard: &str) -> Vec<VcardContact> {
206
206
} else if let Some ( rev) = vcard_property ( line, "rev" ) {
207
207
datetime. get_or_insert ( rev) ;
208
208
} else if line. eq_ignore_ascii_case ( "END:VCARD" ) {
209
+ let ( authname, addr) =
210
+ sanitize_name_and_addr ( display_name. unwrap_or ( "" ) , addr. unwrap_or ( "" ) ) ;
211
+
212
+ contacts. push ( VcardContact {
213
+ authname,
214
+ addr,
215
+ key : key. map ( |s| s. to_string ( ) ) ,
216
+ profile_image : photo. map ( |s| s. to_string ( ) ) ,
217
+ timestamp : datetime
218
+ . context ( "No timestamp in vcard" )
219
+ . and_then ( parse_datetime) ,
220
+ } ) ;
209
221
break ;
210
222
}
211
223
}
212
-
213
- let ( authname, addr) =
214
- sanitize_name_and_addr ( display_name. unwrap_or ( "" ) , addr. unwrap_or ( "" ) ) ;
215
-
216
- contacts. push ( VcardContact {
217
- authname,
218
- addr,
219
- key : key. map ( |s| s. to_string ( ) ) ,
220
- profile_image : photo. map ( |s| s. to_string ( ) ) ,
221
- timestamp : datetime
222
- . context ( "No timestamp in vcard" )
223
- . and_then ( parse_datetime) ,
224
- } ) ;
225
224
}
226
225
227
226
contacts
@@ -540,6 +539,30 @@ END:VCARD",
540
539
assert_eq ! ( contacts. len( ) , 1 ) ;
541
540
}
542
541
542
+ #[ test]
543
+ fn test_vcard_with_trailing_newline ( ) {
544
+ let contacts = parse_vcard (
545
+ "BEGIN:VCARD\r
546
+ VERSION:4.0\r
547
+ FN:Alice Wonderland\r
548
+ N:Wonderland;Alice;;;Ms.\r
549
+ GENDER:W\r
550
+ EMAIL;TYPE=work:alice@example.com\r
551
+ KEY;TYPE=PGP;ENCODING=b:[base64-data]\r
552
+ REV:20240418T184242Z\r
553
+ END:VCARD\r
554
+ \r ",
555
+ ) ;
556
+
557
+ assert_eq ! ( contacts[ 0 ] . addr, "alice@example.com" . to_string( ) ) ;
558
+ assert_eq ! ( contacts[ 0 ] . authname, "Alice Wonderland" . to_string( ) ) ;
559
+ assert_eq ! ( contacts[ 0 ] . key, Some ( "[base64-data]" . to_string( ) ) ) ;
560
+ assert_eq ! ( contacts[ 0 ] . profile_image, None ) ;
561
+ assert_eq ! ( * contacts[ 0 ] . timestamp. as_ref( ) . unwrap( ) , 1713465762 ) ;
562
+
563
+ assert_eq ! ( contacts. len( ) , 1 ) ;
564
+ }
565
+
543
566
#[ test]
544
567
fn test_make_and_parse_vcard ( ) {
545
568
let contacts = [
0 commit comments