diff --git a/CHANGES.rst b/CHANGES.rst index bf6455a..3707365 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -10,6 +10,9 @@ New: Fixes: +- Fixed possible IndexError exception during parsing of an ical string. + [stlaz] + - Fixed date-time being recognized as date or time during parsing. Added better error handling to parsing from ical strings. [stlaz] diff --git a/src/icalendar/cal.py b/src/icalendar/cal.py index 501eeda..4c9e917 100644 --- a/src/icalendar/cal.py +++ b/src/icalendar/cal.py @@ -362,7 +362,10 @@ class Component(CaselessDict): # we are adding properties to the current top of the stack else: factory = types_factory.for_property(name) - component = stack[-1] + component = stack[-1] if stack else None + if not component: + raise ValueError('Property "{prop}" does not have ' + 'a parent component.'.format(prop=name)) datetime_names = ('DTSTART', 'DTEND', 'RECURRENCE-ID', 'DUE', 'FREEBUSY', 'RDATE', 'EXDATE') try: diff --git a/src/icalendar/tests/test_fixed_issues.py b/src/icalendar/tests/test_fixed_issues.py index 97e7f69..7692cb3 100644 --- a/src/icalendar/tests/test_fixed_issues.py +++ b/src/icalendar/tests/test_fixed_issues.py @@ -360,3 +360,12 @@ END:VCALENDAR""" b'DTEND:20150905T100000Z\r\nUID:123\r\n' b'END:VEVENT\r\nEND:VCALENDAR\r\n' ) + + def test_index_error_issue(self): + """ + Found an issue where from_ical() would raise IndexError for properties + without parent components + """ + + with self.assertRaises(ValueError): + cal = icalendar.Calendar.from_ical('VERSION:2.0')