Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser silently ignores multiple N: fields #32

Open
rogarb opened this issue Jun 15, 2022 · 1 comment
Open

Parser silently ignores multiple N: fields #32

rogarb opened this issue Jun 15, 2022 · 1 comment

Comments

@rogarb
Copy link

rogarb commented Jun 15, 2022

Parsing a string containing two name fields ("N:") doesn't produce an error but silently ignores the name fields and produces a VCard with name() returning None:

use vobject::vcard::Vcard;                                                      
                                                                                
fn main() {                                                                     
    let input = "\                                                              
BEGIN:VCARD\r\n\                                                                
VERSION:3.0\r\n\                                                                
FN:Test person\r\n\                                                             
N:Person;Test;;;\r\n\                                                           
N:P;Test;;;\r\n\                                                                
TEL:+30666777888\r\n\                                                           
TEL:+34666777888\r\n\                                                           
TEL:+33666777888\r\n\                                                           
EMAIL;TYPE=INTERNET:[email protected]\r\n\                                    
EMAIL;TYPE=INTERNET:[email protected]\r\n\                                   
END:VCARD\r\n\                                                                  
";                                                                              
    let vcard = Vcard::build(input).unwrap();                                   
    assert!(vcard.name().is_some());                                            
}     

When executed, the code above panics due to the assertion:

thread 'main' panicked at 'assertion failed: vcard.name().is_some()', src/main.rs:18:5

A pretty print shows that both "N:" fields are effectively parsed and added to the underlying Component:

Vcard(
    Component {
        name: "VCARD",
        props: {
           [...]
            "N": [
                Property {
                    name: "N",
                    params: {},
                    raw_value: "Person;Test;;;",
                    prop_group: None,
                },
                Property {
                    name: "N",
                    params: {},
                    raw_value: "P;Test;;;",
                    prop_group: None,
                },
            ],
           [...]
        },
        subcomponents: [],
    },
)

Shouldn't either the parser return a parsing error or name() return Some(Name)?

@lucc
Copy link

lucc commented Jul 26, 2024

I think the problem is that vcard.name() is implemented by make_getter_function_for_optional! but it should be implemented by make_getter_function_for_values! instead. If you read these macros you can see that you might be able to get all N values with something like vcard.get_all("N").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants