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

Issues if dealing with vcf with multiple cards #11

Closed
ajmas opened this issue Dec 26, 2016 · 12 comments
Closed

Issues if dealing with vcf with multiple cards #11

ajmas opened this issue Dec 26, 2016 · 12 comments

Comments

@ajmas
Copy link
Contributor

ajmas commented Dec 26, 2016

The library appears to run into issues if a vcf file contains multiple vCards. What I see is the records from all the vCards are merged into one entry.

For example (trimmed):

vCard {
  version: '3.0',
  data: 
   { version: 
      [ [String: '3.0'],
        [String: '3.0'],
        [String: '3.0'],
        [String: '3.0'],
        [String: '3.0'],
        [String: '3.0'],
        [String: '3.0'],
        [String: '3.0'],
        [String: '3.0'],
        [String: '3.0'],
        [String: '3.0'],
        [String: '3.0'],
        [String: '3.0'],
        [String: '3.0'] ],
     prodid: 
      [ [String: '-//Apple Inc.//Mac OS X 10.12.1//EN'],
        [String: '-//Apple Inc.//Mac OS X 10.12.1//EN'],
        [String: '-//Apple Inc.//Mac OS X 10.12.1//EN'],
        [String: '-//Apple Inc.//Mac OS X 10.12.1//EN'],
        [String: '-//Apple Inc.//Mac OS X 10.12.1//EN'],
        [String: '-//Apple Inc.//Mac OS X 10.12.1//EN'],
        [String: '-//Apple Inc.//Mac OS X 10.12.1//EN'],
        [String: '-//Apple Inc.//Mac OS X 10.12.1//EN'],
        [String: '-//Apple Inc.//Mac OS X 10.12.1//EN'],
        [String: '-//Apple Inc.//Mac OS X 10.12.1//EN'],
        [String: '-//Apple Inc.//Mac OS X 10.12.1//EN'],
        [String: '-//Apple Inc.//Mac OS X 10.12.1//EN'],
        [String: '-//Apple Inc.//Mac OS X 10.12.1//EN'],
        [String: '-//Apple Inc.//Mac OS X 10.12.1//EN'] ],
     n: 
      [ [String: 'Matters;Sylvie;;;'],
        [String: 'Dawson;Jesse;;;'],
        [String: 'Kelsdaughter;Jen;;;'],
        [String: ';;;;'],
        [String: 'Jameson;Jen;;;'],
        [String: ';;;;'],
        [String: 'Dawson;Marc;;;'],
        [String: ';Agathe;;;'],
        [String: ';;;;'],
        [String: 'Doe;John;;;'],
        [String: 'Vino;Vito;;;'],
        [String: ';Alexei;;;'],
        [String: 'Boucher;Marie-Claude;;;'],
        [String: ';;;;'] ],
...

It would be useful to have this scenario supported, even if it via a new function parseMulti() , as to not break assumptions of code depending on current design.

@ajmas
Copy link
Contributor Author

ajmas commented Dec 26, 2016

Looking at the source I see parseMultiple() already exists. Testing shows this is what I should be using.

@ajmas ajmas closed this as completed Dec 26, 2016
@jwerre
Copy link

jwerre commented Jun 24, 2017

This should just be the default. Why would want to combine all your contacts into one object?

@jhermsmeier
Copy link
Owner

@jwerre If you think this needs changing, then please do file a new issue, or – even better – send a PR.

@ajmas
Copy link
Contributor Author

ajmas commented Jun 24, 2017

@jhermsmeier Is there any benefit of using parse() over parseMultiple()?

BTW a simple fix would simply to update the readme with indication of parseMultiple(). One risk of changing the default behaviour of parse() is breaking existing code, that assumes a single, non-array, object is returned.

@jhermsmeier
Copy link
Owner

@ajmas to be honest, I don't recall what the reasoning behind it was. I'm more than happy to change the API to default to parsing multiple objects from an input for the static vCard.parse(), which will of course make it version 2.0.0 as it's a breaking change, as that seems to be what people expect and would rather like to use.

@ajmas
Copy link
Contributor Author

ajmas commented Jun 24, 2017

@jhermsmeier okay sounds good. In the meantime do you think the PR for the documentation change for the 1.x branch is an acceptable stop-gap?

@jhermsmeier
Copy link
Owner

@ajmas yup, just reviewed :)

@jhermsmeier
Copy link
Owner

@ajmas want to have a look at #15, and tell me if I missed anything?

@zacharytyhacz
Copy link

This issue is still is still persisting for me.

Using "vcf": "^2.0.4"

I am parsing this that is straight from Google Contacts:

BEGIN:VCARD
VERSION:3.0
FN:Bolt Action
N:Action;Bolt;;;
item1.EMAIL;TYPE=INTERNET:boltaction@mmmm.com
item1.X-ABLabel:
END:VCARD
BEGIN:VCARD
VERSION:3.0
FN:Brenna Damatta
N:Damatta;Brenna;;;
item1.EMAIL;TYPE=INTERNET:brenna@mmmm.com
item1.X-ABLabel:
END:VCARD

It is returning one vcard object merging the fn, adr, n, etc ,etc making it extra verbose to loop through and separate out the date per contact.

Each field is an array containing data from both contacts.
image

@jhermsmeier
Copy link
Owner

@zacharytyhacz I suspect that's happening because you're calling .parse() on a vCard instance, not on the constructor. Note the difference between parsing a single vcard and parsing multiple vcards in the README

@zacharytyhacz
Copy link

@jhermsmeier , yes that is the method I used, .parse. I have a work around at the moment, using the same ReGex you use in the source to seperate the file at BEGIN:VCARD and then individually parsing each as a single vcard with the other new vCard().parse(<source>)

@jhermsmeier
Copy link
Owner

@zacharytyhacz can you post an example of what you're doing? I cannot reproduce that in any way, i.e. see:

> var vCard = require( '.' )
undefined

> var value = `BEGIN:VCARD
... VERSION:3.0
... FN:Bolt Action
... N:Action;Bolt;;;
... item1.EMAIL;TYPE=INTERNET:boltaction@mmmm.com
... item1.X-ABLabel:
... END:VCARD
... BEGIN:VCARD
... VERSION:3.0
... FN:Brenna Damatta
... N:Damatta;Brenna;;;
... item1.EMAIL;TYPE=INTERNET:brenna@mmmm.com
... item1.X-ABLabel:
... END:VCARD`
undefined

> vCard.parse( value )
[
  vCard {
    version: '3.0',
    data: {
      version: Property {},
      fn: Property {},
      n: Property {},
      email: [Property]
    }
  },
  vCard {
    version: '3.0',
    data: {
      version: Property {},
      fn: Property {},
      n: Property {},
      email: [Property]
    }
  }
]

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

4 participants