Skip to content

Commit

Permalink
Make sure there is only one instance of prodid, rev and uid
Browse files Browse the repository at this point in the history
Multiple prodid causes vobject to crash at serialization, but there should
also be at most one instance of rev and uid, according to
https://tools.ietf.org/html/rfc6350, so check those properties as well
  • Loading branch information
agateau committed Mar 19, 2017
1 parent 2d0b4af commit 20f3cb2
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions vcardlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
OPTION_UPDATE_GROUP_KEY = True
OPTION_FRENCH_TWEAKS = False

SINGLE_INSTANCE_PROPERTIES = {'prodid', 'rev', 'uid'}

def add_attributes(attributes, a):
"""
Return void
Expand Down Expand Up @@ -382,6 +384,9 @@ def build_vcard(attributes):

logging.debug("Building vcard ...")
vcard = vCard()

defined_single_instance_properties = set()

for a_name, a in attributes.items():
#logging.debug("\tprocessing '%s' -> '%s'", a_name, a)
if a:
Expand Down Expand Up @@ -430,6 +435,11 @@ def build_vcard(attributes):
vcard.add(a_name).value = a_item
logging.debug("\t%s: %s", a_name, a_item)
elif isinstance(a_item, ContentLine):
if a_name in SINGLE_INSTANCE_PROPERTIES:
if a_name in defined_single_instance_properties:
continue
else:
defined_single_instance_properties.add(a_name)
item_added = vcard.add(a_name)
logging.debug("\t%s: %s", a_name, a_item.value)
item_added.value = a_item.value
Expand Down

0 comments on commit 20f3cb2

Please sign in to comment.