riboseinc / ruby-vobject

Ruby library for parsing vObjects
BSD 2-Clause "Simplified" License
10 stars 3 forks source link

Type mismatch for property VERSION, value 2.1 #21

Open dima4p opened 1 year ago

dima4p commented 1 year ago
require 'vcard'
vcf = File.read <source file>

The source file is

BEGIN:VCARD
VERSION:2.1
N:;we;;;
FN:we
EMAIL;PREF:hr_rus@wecommunicate.co
END:VCARD
> cs = Vcard.parse vcf, '3.0', true
/usr/local/rvm/gems/ruby-3.2.2@koulikoff/gems/vobject-1.1.0/lib/vobject/vcard/v3_0/typegrammars.rb:418:in `parse_err': Type mismatch for property VERSION, value 2.1 (Rsec::SyntaxError)
in source:3 at 1
N:;we;;;
 ^
        from /usr/local/rvm/gems/ruby-3.2.2@koulikoff/gems/vobject-1.1.0/lib/vobject/vcard/v3_0/typegrammars.rb:408:in `typematch'
        from /usr/local/rvm/gems/ruby-3.2.2@koulikoff/gems/vobject-1.1.0/lib/vobject/vcard/v3_0/grammar.rb:129:in `block in vobject_grammar'
        from /usr/local/rvm/gems/ruby-3.2.2@koulikoff/gems/rsec-1.0.0/lib/rsec/parsers/misc.rb:8:in `_parse'
        from /usr/local/rvm/gems/ruby-3.2.2@koulikoff/gems/rsec-1.0.0/lib/rsec/parsers/seq.rb:64:in `block in _parse'
....

Please, help to fix. Ruby 3.2.2.

ronaldtse commented 1 year ago

@dima4p thank you for the report!

@opoudjis @CAMOBAP do you know what the issue is? Thanks.

CAMOBAP commented 1 year ago

@ronaldtse @dima4p To me it looks like our parser support only 3.0 or 4.0 versions. I'm not sure about backward compatibility between 2.1 and 3.0 but probably they aren't compatible

@ronaldtse should we support versions before 3.0 @dima4p is it important for you to parse 2.1 version or you can upgrade your object source to 3.0 or above?

dima4p commented 1 year ago

@dima4p is it important for you to parse 2.1 version or you can upgrade your object source to 3.0 or above?

yes, it is what google contacts returns.

opoudjis commented 1 year ago

https://github.com/jowave/vcard2to3

The showstopper issue between vCard 2.1 and vCard 3.0 is that FN goes from optional to mandatory, and the "TYPE=" is omitted for type attributes. The latter is catered for by the Python script above. If your source has FN (and it looks like it does), then using the Python script should make for acceptable results.