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

VCard: Parse Error with multiline list-type notes #8

Closed
minthemiddle opened this issue Feb 5, 2016 · 2 comments
Closed

VCard: Parse Error with multiline list-type notes #8

minthemiddle opened this issue Feb 5, 2016 · 2 comments

Comments

@minthemiddle
Copy link

I categorize my contacts via VCard's notes field. I enter them as lists, such as:

- List1
- List2
- List3

When I enter such a VCard, it will fail to parse:

VCARD:

s = """
BEGIN:VCARD
VERSION:3.0
PRODID:-//Apple Inc.//Mac OS X 10.11.3//EN
N:XXX;;;
FN:XX XX
EMAIL;type=INTERNET;type=HOME;type=pref:xxx@gmail.com
TEL;type=CELL;type=VOICE;type=pref:+4915773321986
ADR;type=HOME;type=pref:;;;Berlin;Berlin;;Germany
BDAY:1986-11-17
UID:e0355606-117f-4388-bb6d-eda3a1f6449d
X-ABUID:E0355606-117F-4388-BB6D-EDA3A1F6449D:ABPerson
NOTE:- List1\n- List2 \n- List3
END:VCARD
"""

COMMAND:

from vobject import vCard, readOne
v = readOne(s)

ERROR:

---------------------------------------------------------------------------
ParseError                                Traceback (most recent call last)
<ipython-input-21-61222ae13dcb> in <module>()
----> 1 v = readOne(s)

/usr/local/lib/python3.5/site-packages/vobject/base.py in readOne(stream, validate, transform, ignoreUnreadable, allowQP)
   1096     """
   1097     return next(readComponents(stream, validate, transform, ignoreUnreadable,
-> 1098                                allowQP))
   1099 
   1100 

/usr/local/lib/python3.5/site-packages/vobject/base.py in readComponents(streamOrString, validate, transform, ignoreUnreadable, allowQP)
   1040                     continue
   1041             else:
-> 1042                 vline = textLineToContentLine(line, n)
   1043             if vline.name == "VERSION":
   1044                 versionLine = vline

/usr/local/lib/python3.5/site-packages/vobject/base.py in textLineToContentLine(text, n)
    880 
    881 def textLineToContentLine(text, n=None):
--> 882     return ContentLine(*parseLine(text, n), **{'encoded':True,
    883                                                'lineNumber' : n})
    884 

/usr/local/lib/python3.5/site-packages/vobject/base.py in parseLine(line, lineNumber)
    769     match = line_re.match(line)
    770     if match is None:
--> 771         raise ParseError("Failed to parse line: {0!s}".format(line), lineNumber)
    772     # Underscores are replaced with dash to work around Lotus Notes
    773     return (match.group('name').replace('_','-'),

ParseError: At line 14: Failed to parse line: - List2 
@minthemiddle minthemiddle changed the title Parse Error with multiline list-type notes VCard: Parse Error with multiline list-type notes Feb 5, 2016
@minthemiddle
Copy link
Author

It's got to do with \n-, newline and dash. The regex fails. When I enter an additional whitespace in between, it works. But I think it should be possible to start a line in notes with -.

@wpercy
Copy link
Contributor

wpercy commented Jun 22, 2017

This is actually happening because of how docstrings (multi-line strings) work with newlines. If I read that same vCard in from a file, it works just fine. What happens is that the newlines get interpreted before vObject has a chance to read in the lines, so your vCard looks like this:

BEGIN:VCARD
VERSION:3.0
PRODID:-//Apple Inc.//Mac OS X 10.11.3//EN
N:XXX;;;
FN:XX XX
EMAIL;type=INTERNET;type=HOME;type=pref:xxx@gmail.com
TEL;type=CELL;type=VOICE;type=pref:+4915773321986
ADR;type=HOME;type=pref:;;;Berlin;Berlin;;Germany
BDAY:1986-11-17
UID:e0355606-117f-4388-bb6d-eda3a1f6449d
X-ABUID:E0355606-117F-4388-BB6D-EDA3A1F6449D:ABPerson
NOTE:- List1
- List2      # THIS LINE IS INVALID
- List3
END:VCARD

which is obviously invalid due to the line I pointed out.

If you want to perform the operation like you do above (using a multi-line string), you need to escape all of your newlines in your NOTE property with an extra backslash so they look like \\n.

@wpercy wpercy closed this as completed Jun 22, 2017
lucc pushed a commit to lucc/vobject that referenced this issue Apr 9, 2024
Import `basestring` from `.base`
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