diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a7b5061..bb89a5f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ This project should more or less adhere to [Semantic Versioning](https://semver. * There were some compatibility-logic loading objects if the server does not deliver icalendar data (as it's suppsoed to do according to the RFC), but only if passing the `expand`-flag to the `search`-method. Fixed that it loads regardless of weather `expand` is set or not. Also in https://github.com/python-caldav/caldav/pull/366 * Tests - a breakage was introduced for servers not supporting MKCALENDAR - details in https://github.com/python-caldav/caldav/pull/368 * Tests - all tests passes for python 3.12 as well - as expected. +* The vcal fixup method was converting implicit dates into timestamps in the COMPLETED property, as it should be a timestamp according to the RFC - however, the regexp failed on explicit dates. Now it will take explicit dates too. ### Changed diff --git a/caldav/lib/vcal.py b/caldav/lib/vcal.py index 5e1500d9..deee960a 100644 --- a/caldav/lib/vcal.py +++ b/caldav/lib/vcal.py @@ -31,7 +31,8 @@ def fix(event): breakages with the standard, and attempts to fix up known issues: 1) COMPLETED MUST be a datetime in UTC according to the RFC, but sometimes - a date is given. (Google Calendar?) + a date is given. (Google Calendar?) SOGo! Ref https://github.com/home-assistant/core/issues/106671 + 2) The RFC does not specify any range restrictions on the dates, but clearly it doesn't make sense with a CREATED-timestamp that is @@ -63,7 +64,7 @@ def fix(event): ## TODO: add ^ before COMPLETED and CREATED? ## 1) Add an arbitrary time if completed is given as date - fixed = re.sub(r"COMPLETED:(\d+)\s", r"COMPLETED:\g<1>T120000Z", event) + fixed = re.sub(r"COMPLETED(?:;VALUE=DATE)?:(\d+)\s", r"COMPLETED:\g<1>T120000Z", event) ## 2) CREATED timestamps prior to epoch does not make sense, ## change from year 0001 to epoch. diff --git a/tests/test_vcal.py b/tests/test_vcal.py index b5bc2470..7a57513e 100644 --- a/tests/test_vcal.py +++ b/tests/test_vcal.py @@ -248,12 +248,39 @@ def test_vcal_fixups(self): DESCRIPTION:Reminder END:VALARM END:VEVENT -END:VCALENDAR""", +END:VCALENDAR""", ## next has a completed date. It should be a timestamp according to the RFC +"""BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//Example Corp.//CalDAV Client//EN +BEGIN:VTODO +UID:20070313T123432Z-456553@example.com +DTSTAMP:20070313T123432Z +COMPLETED;VALUE=DATE:20070501 +SUMMARY:Submit Quebec Income Tax Return for 2006 +CLASS:CONFIDENTIAL +CATEGORIES:FAMILY,FINANCE +STATUS:NEEDS-ACTION +END:VTODO +END:VCALENDAR""", ## Again, but implicit instead of explicit date +"""BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//Example Corp.//CalDAV Client//EN +BEGIN:VTODO +UID:20070313T123432Z-456553@example.com +DTSTAMP:20070313T123432Z +COMPLETED:20070501 +SUMMARY:Submit Quebec Income Tax Return for 2006 +CLASS:CONFIDENTIAL +CATEGORIES:FAMILY,FINANCE +STATUS:NEEDS-ACTION +END:VTODO +END:VCALENDAR""" ] ## todo: add more broken ical here for ical in broken_ical: ## This should raise error - with pytest.raises(vobject.base.ValidateError): + #with pytest.raises(vobject.base.ValidateError): + with pytest.raises(Exception): vobject.readOne(ical).serialize() ## This should not raise error vobject.readOne(vcal.fix(ical)).serialize()