Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tobixen committed Mar 27, 2024
1 parent eb22b33 commit e70cb28
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,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

Expand Down
7 changes: 5 additions & 2 deletions caldav/lib/vcal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -63,7 +64,9 @@ 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.
Expand Down
4 changes: 2 additions & 2 deletions tests/test_caldav.py
Original file line number Diff line number Diff line change
Expand Up @@ -1297,9 +1297,9 @@ def testSearchEvent(self):
start=datetime(2006, 7, 13, 13, 0),
end=datetime(2006, 7, 15, 13, 0),
)
if (not self.check_compatibility_flag(
if not self.check_compatibility_flag(
"category_search_yields_nothing"
) and not self.check_compatibility_flag("combined_search_not_working")):
) and not self.check_compatibility_flag("combined_search_not_working"):
assert len(no_events) == 0
some_events = c.search(
comp_class=Event,
Expand Down
29 changes: 28 additions & 1 deletion tests/test_vcal.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,39 @@ def test_vcal_fixups(self):
DESCRIPTION:Reminder
END:VALARM
END:VEVENT
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:[email protected]
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:[email protected]
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()
Expand Down

0 comments on commit e70cb28

Please sign in to comment.