diff --git a/parsers/src/vcard.rs b/parsers/src/vcard.rs index 11170b7c..7f415078 100644 --- a/parsers/src/vcard.rs +++ b/parsers/src/vcard.rs @@ -14,7 +14,7 @@ //! see [`vcard_update`][crate::vcard_update] module. use crate::iq::{IqGetPayload, IqResultPayload, IqSetPayload}; -use crate::util::text_node_codecs::{Base64, Codec, Text}; +use crate::util::text_node_codecs::{Codec, Text, WhitespaceAwareBase64}; use crate::{ns, Error}; use minidom::Element; @@ -44,7 +44,7 @@ generate_element!( Binval, "BINVAL", VCARD, text: ( /// The actual data. - data: Base64 + data: WhitespaceAwareBase64 ) ); @@ -131,4 +131,34 @@ mod tests { assert_eq!(photo.type_.data, "image/jpeg".to_string()); assert_eq!(photo.binval.data, bytes); } + + #[test] + fn test_vcard_with_linebreaks() { + // Test xml stolen from https://xmpp.org/extensions/xep-0153.html#example-5 + // extended to use a multi-line base64 string as is allowed as per RFC 2426 + let test_vcard = r" + 1476-06-09 + + Italy + Verona + + + + JulietCapulet + jcapulet@shakespeare.lit + + image/jpeg + Zm9v +Cg== + + "; + + let test_vcard = Element::from_str(&test_vcard).expect("Failed to parse XML"); + let test_vcard = VCard::try_from(test_vcard).expect("Failed to parse vCard"); + + let photo = test_vcard.photo.expect("No photo found"); + + assert_eq!(photo.type_.data, "image/jpeg".to_string()); + assert_eq!(photo.binval.data, b"foo\n"); + } }