Correctly handle multiline UIDs

See #74
This commit is contained in:
Markus Unterwaditzer 2014-06-11 18:28:51 +02:00
parent 764a10ca0a
commit cec742b9e3
2 changed files with 17 additions and 0 deletions

View file

@ -85,3 +85,11 @@ def test_hash_item():
b = u'\n'.join(line for line in a.splitlines()
if u'PRODID' not in line and u'VERSION' not in line)
assert vobject.hash_item(a) == vobject.hash_item(b)
def test_multiline_uid():
a = (u'BEGIN:FOO\r\n'
u'UID:123456789abcd\r\n'
u' efgh\r\n'
u'END:FOO\r\n')
assert vobject.Item(a).uid == u'123456789abcdefgh'

View file

@ -91,6 +91,15 @@ class Item(object):
def uid(self):
'''Global identifier of the item, across storages, doesn't change after
a modification of the item.'''
stack = [self.parsed]
while stack:
component = stack.pop()
if not component:
continue
uid = component.get('UID', None)
if uid:
return uid
stack.extend(component.subcomponents)
for line in self.raw.splitlines():
if line.startswith(u'UID:'):