skarim / vobject

A full-featured Python package for parsing and creating iCalendar and vCard files
https://vobject.sameenkarim.com
255 stars 93 forks source link

vobject chokes on '<TRIGGER{}PT>' #96

Open Achimh3011 opened 7 years ago

Achimh3011 commented 7 years ago

Parsing an event from a Zimbra server, vobject chokes on the definition of a TRIGGER as PT. PT normally would start a DURATION, but here none is specified.

Would it make sense to accept this input and interpret it as "no trigger"?

wpercy commented 7 years ago

I don't think so. That seems like a malformed alarm component to me. From the RFC 5545 spec for "TRIGGER":

Conformance: This property MUST be specified in the "VALARM" calendar component.

You can't have a "VALARM" component without a trigger, so how can we accept any input as "no trigger"? It wouldn't conform to the spec.

Achimh3011 commented 7 years ago

Understood.

My problem is that such a (wrong) tag will probably show up again. And then again, an entire search on an calendar breaks, rendering the functionality useless.

Or do I miss a possibility to make the parsing not break completely? I use vobject via the caldav library.

wpercy commented 7 years ago

That's a very good point, and why I wanted to keep the issue open - get a little more discussion here. What would you suggest we do? Drop the entire VALARM component? I don't know how most calendar clients would react to a VALARM component with a malformed TRIGGER.

Unfortunately I can't really speak to the caldav library, that's something you'd have to ask them.

Achimh3011 commented 7 years ago

I think dropping the VALARM component in this case would be a valid consequence.

wpercy commented 6 years ago

@Achimh3011 can you provide the event that fails to parse because of a bad TRIGGER?

Achimh3011 commented 6 years ago

I don't have the original event any more. I tried to construct an equivalent one (attached) but when I import it into my calendar (via Apple Calendar / zimbra), caldav/vobject do not have a problem with it.

Reading it directly provokes the error as expected, though:

with open('iCal-20180720-121457.ics') as inp:
    cal = vobject.readOne(inp)

yields

scratch_1.py
Traceback (most recent call last):
  File "~/prog/vobject/vobject/icalendar.py", line 1388, in transformToNative
    return Duration.transformToNative(obj)~
  File "~/prog/vobject/vobject/icalendar.py", line 1349, in transformToNative
    raise ParseError("DURATION must have a single duration string.")
vobject.base.ParseError: 'DURATION must have a single duration string.'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "~/prog/vobject/vobject/icalendar.py", line 1617, in stringToDateTime
    year   = int( s[0:4] )
ValueError: invalid literal for int() with base 10: 'PT'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "~/prog/vobject/vobject/icalendar.py", line 1395, in transformToNative
    dt = DateTimeBehavior.transformToNative(obj)
  File "~/prog/vobject/vobject/icalendar.py", line 720, in transformToNative
    obj.value=parseDtstart(obj)
  File "~/prog/vobject/vobject/icalendar.py", line 1839, in parseDtstart
    return stringToDateTime(contentline.value, tzinfo)
  File "~/prog/vobject/vobject/icalendar.py", line 1627, in stringToDateTime
    raise ParseError("'{0!s}' is not a valid DATE-TIME".format(s))
vobject.base.ParseError: "'PT' is not a valid DATE-TIME"

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "~/Library/Preferences/PyCharm2018.1/scratches/scratch_1.py", line 5, in <module>
    cal = vobject.readOne(inp)
  File "~/prog/vobject/vobject/base.py", line 1130, in readOne
    allowQP))
  File "~/prog/vobject/vobject/base.py", line 1102, in readComponents
    component.transformChildrenToNative()
  File "~/prog/vobject/vobject/base.py", line 662, in transformChildrenToNative
    child.transformChildrenToNative()
  File "~/prog/vobject/vobject/base.py", line 662, in transformChildrenToNative
    child.transformChildrenToNative()
  File "~/prog/vobject/vobject/base.py", line 661, in transformChildrenToNative
    child = child.transformToNative()
  File "~/prog/vobject/vobject/base.py", line 183, in transformToNative
    return self.behavior.transformToNative(self)
  File "~/prog/vobject/vobject/icalendar.py", line 1400, in transformToNative
    raise ParseError(msg)
vobject.base.ParseError: At line 36: TRIGGER with no VALUE not recognized as DURATION or as DATE-TIME

Process finished with exit code 1

iCal-20180720-121457.ics.txt