kenianbei / vcard_parser

Parses and validates vCard data according to RFC 6350 specification.
MIT License
6 stars 3 forks source link

get_property_by_type return None for some type #11

Closed Cyrix126 closed 1 year ago

Cyrix126 commented 2 years ago

I encounter an issue where get_property_by_type doesn't find the property for some types (tested on Email, Tel, Lang).

For example this code:

use vcard_parser::vcard::property::types::PropertyType;
use vcard_parser::vcard::Vcard;

fn main() {
let mut vcard = Vcard::default();
vcard.add_property("EMAIL:test@test.com").expect("Unable to add property.");
let _property = vcard.get_property_by_type(&PropertyType::Email).unwrap();
}

Will compile but if ran it will panic because thread 'main' panicked at 'called Option::unwrap() on a None value', src/main.rs:7:66

get_property_by_type return None where it should return the property just added. The add_property works, if I return vcard as a string, I can see the new property. But for some reason the get_property_by_type can't retrieve it.

kenianbei commented 2 years ago

Hi, this is not obvious in the doc, but this method only works for single properties. For properties that have multiple cardinality like email, tel, you have to use get_properties_by_type.

I'm thinking about completely reworking how properties are matched, to more closely follow the spec, see https://github.com/kenianbei/vcard_parser/issues/8. I'll keep this issue open for now to discuss a better way to get properties from the vcard.

Cyrix126 commented 2 years ago

ok, thanks for clearing that up.