l0b0 / vcard

vCard 3 validator, class and utility functions
https://gitlab.com/victor-engmark/vcard
GNU General Public License v3.0
34 stars 8 forks source link

VCardFormatError: Invalid line ending #2

Closed eadmaster closed 12 years ago

eadmaster commented 12 years ago

code:

    for f in args:
        file_opened = open(f, "r")
        result = VCard(file_opened.read())
        if result is not None:
            print(result + '\n')

error:

Traceback (most recent call last):
  File "vcard.py", line 471, in 
    sys.exit(main())
  File "vcard.py", line 465, in main
    result = VCard(file_opened.read())
  File "vcard.py", line 360, in __init__
    lines = unfold_vcard_lines(self.text.splitlines(True))
  File "vcard.py", line 65, in unfold_vcard_lines
    {'File line': index + 1})
vcard_validators.VCardFormatError: Invalid line ending; should be \r\n (See RFC
2426 section 2.4.2 for details)
File line: 1

The actual line endings seems correct. The same vcard parses just fine in other programs.

EDIT: opening the file with "codecs.open(f, 'r', 'utf-8')" fixed the newline issue, but now i'm getting

vcard_validators.VCardFormatError: Invalid value count (See RFC 2426 section 3 for details): 2 (expected 5)
vCard line: 2
Property: N
Property line: N:Surname;Name
l0b0 commented 12 years ago

Regarding the line endings, it's hard to tell without the actual file. Virtually all vCards I've found on the web contain what is probably considered minor errors, which means they can only be handled by sufficiently fuzzy parsers. This program was written for those who wanted strict validation, to be able to use stricter (and thus simpler) parsers and to ensure maximum compatibility across fuzzy parsers.

The N property does consist of exactly 5 values. From RFC 2426 section 3:

The structured type value corresponds, in sequence, to the Family Name, Given Name, Additional Names, Honorific Prefixes, and Honorific Suffixes. The text components are separated by the SEMI-COLON character (ASCII decimal 59).

Example (including multiple pre- and postfixes):

N:Doe;John;Samuel;Mr,Dr;Sr,Esquire