python-caldav / caldav

Apache License 2.0
318 stars 95 forks source link

URL Handling with Absolute URLs #435

Open ScottPeterJohnson opened 1 week ago

ScottPeterJohnson commented 1 week ago

Per advice of RFC 4918, Webdav paths returned in a multistatus element should be either path-absolute (/sample/) or absolute (http://example.com/sample/).

Purelymail has a custom implementation of CalDAV that uses absolute URIs, resulting in issues using the CalDAV library:

`Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 361, in _async_setup_platform await asyncio.shield(awaitable) File "/usr/src/homeassistant/homeassistant/components/caldav/calendar.py", line 149, in async_setup_entry calendars = await async_get_calendars(hass, client, SUPPORTED_COMPONENT) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/caldav/api.py", line 20, in async_get_calendars return await hass.async_add_executor_job(_get_calendars) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/caldav/api.py", line 17, in _get_calendars if component in calendar.get_supported_components() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/caldav/objects.py", line 709, in get_supported_components prop = response_list[unquote(self.url.path)][


KeyError: '/webdav/N/caldav/default/'`

I don't know much Python, but to fix this maybe just needs an `unquote(urlparse().path)` here?
https://github.com/python-caldav/caldav/blob/4c381834953b0d64a2afbc0ad0b6268670e56883/caldav/davclient.py#L222
tobixen commented 1 week ago

I'm quite overloaded at the moment, so I don't think I have time for looking into this myself in the near future - but if you write up a pull request, I will check if the test code passes towards the test servers I have available, and if there are no problems there I will check up a bit and most likely include it in the next release.

Is Purelymail a cloud offering or some software to be run on-premise? Is it possible to create a dedicated test account that can be used for running the functional test?