Check that vobject_item have a UID
This commit is contained in:
parent
fe97741f08
commit
2860c664d0
@ -788,6 +788,8 @@ class Application:
|
||||
|
||||
try:
|
||||
items = list(vobject.readComponents(content or ""))
|
||||
for item in items:
|
||||
storage.check_item(item)
|
||||
except Exception as e:
|
||||
self.logger.warning(
|
||||
"Bad PUT request on %r: %s", path, e, exc_info=True)
|
||||
|
@ -114,6 +114,20 @@ def load(configuration, logger):
|
||||
return CollectionCopy
|
||||
|
||||
|
||||
def check_item(vobject_item):
|
||||
"""Check vobject items for common errors."""
|
||||
if vobject_item.name == "VCALENDAR":
|
||||
for component in vobject_item.components():
|
||||
if (component.name in ("VTODO", "VEVENT", "VJOURNAL") and
|
||||
not get_uid(component)):
|
||||
raise ValueError("UID in %s is missing" % component.name)
|
||||
elif vobject_item.name == "VCARD":
|
||||
if not get_uid(vobject_item):
|
||||
raise ValueError("UID in VCARD is missing")
|
||||
else:
|
||||
raise ValueError("Unknown item type: %r" % vobject_item.name)
|
||||
|
||||
|
||||
def scandir(path, only_dirs=False, only_files=False):
|
||||
"""Iterator for directory elements. (For compatibility with Python < 3.5)
|
||||
|
||||
@ -986,8 +1000,13 @@ class Collection(BaseCollection):
|
||||
cinput_hash = cetag = ctext = ctag = cstart = cend = None
|
||||
vobject_item = None
|
||||
if input_hash != cinput_hash:
|
||||
vobject_item = Item(self, href=href,
|
||||
text=btext.decode(self.encoding)).item
|
||||
try:
|
||||
vobject_item = Item(self, href=href,
|
||||
text=btext.decode(self.encoding)).item
|
||||
check_item(vobject_item)
|
||||
except Exception as e:
|
||||
raise RuntimeError("Failed to parse item %r from %r: %s" %
|
||||
(href, self.path, e)) from e
|
||||
# Serialize the object again, to normalize the text representation.
|
||||
# The storage may have been edited externally.
|
||||
ctext = vobject_item.serialize()
|
||||
|
@ -23,5 +23,6 @@ BEGIN:VTODO
|
||||
DTSTART;TZID=Europe/Paris:20130901T180000
|
||||
DUE;TZID=Europe/Paris:20130903T180000
|
||||
RRULE:FREQ=MONTHLY
|
||||
UID:todo2
|
||||
END:VTODO
|
||||
END:VCALENDAR
|
||||
|
@ -21,5 +21,6 @@ END:STANDARD
|
||||
END:VTIMEZONE
|
||||
BEGIN:VTODO
|
||||
DTSTART;TZID=Europe/Paris:20130901T180000
|
||||
UID:todo3
|
||||
END:VTODO
|
||||
END:VCALENDAR
|
||||
|
@ -21,5 +21,6 @@ END:STANDARD
|
||||
END:VTIMEZONE
|
||||
BEGIN:VTODO
|
||||
DUE;TZID=Europe/Paris:20130901T180000
|
||||
UID:todo4
|
||||
END:VTODO
|
||||
END:VCALENDAR
|
||||
|
@ -22,5 +22,6 @@ END:VTIMEZONE
|
||||
BEGIN:VTODO
|
||||
CREATED;TZID=Europe/Paris:20130903T180000
|
||||
COMPLETED;TZID=Europe/Paris:20130920T180000
|
||||
UID:todo5
|
||||
END:VTODO
|
||||
END:VCALENDAR
|
||||
|
@ -21,5 +21,6 @@ END:STANDARD
|
||||
END:VTIMEZONE
|
||||
BEGIN:VTODO
|
||||
COMPLETED;TZID=Europe/Paris:20130920T180000
|
||||
UID:todo6
|
||||
END:VTODO
|
||||
END:VCALENDAR
|
||||
|
@ -21,5 +21,6 @@ END:STANDARD
|
||||
END:VTIMEZONE
|
||||
BEGIN:VTODO
|
||||
CREATED;TZID=Europe/Paris:20130803T180000
|
||||
UID:todo7
|
||||
END:VTODO
|
||||
END:VCALENDAR
|
||||
|
@ -20,6 +20,6 @@ RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
|
||||
END:STANDARD
|
||||
END:VTIMEZONE
|
||||
BEGIN:VTODO
|
||||
|
||||
UID:todo8
|
||||
END:VTODO
|
||||
END:VCALENDAR
|
||||
|
Loading…
Reference in New Issue
Block a user