Skip to content

Commit 76dc9dc

Browse files
authored
Merge pull request #1465 from metallerok/processing-expand-property
Validation fixes for processing expand property
2 parents 06a95d7 + f0e21b1 commit 76dc9dc

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

radicale/app/report.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
import socket
2525
import xml.etree.ElementTree as ET
2626
from http import client
27-
from typing import Callable, Iterable, Iterator, Optional, Sequence, Tuple
27+
from typing import (Callable, Iterable, Iterator, List, Optional, Sequence,
28+
Tuple, Union)
2829
from urllib.parse import unquote, urlparse
2930

31+
import vobject.base
3032
from vobject.base import ContentLine
3133

3234
import radicale.item as radicale_item
@@ -69,7 +71,7 @@ def xml_report(base_prefix: str, path: str, xml_request: Optional[ET.Element],
6971
xmlutils.make_human_tag(root.tag), path)
7072
return client.FORBIDDEN, xmlutils.webdav_error("D:supported-report")
7173

72-
props = root.find(xmlutils.make_clark("D:prop")) or []
74+
props: Union[ET.Element, List] = root.find(xmlutils.make_clark("D:prop")) or []
7375

7476
hreferences: Iterable[str]
7577
if root.tag in (
@@ -203,21 +205,21 @@ def _expand(
203205
if rruleset:
204206
recurrences = rruleset.between(start, end)
205207

206-
expanded = None
207-
for recurrence_dt in recurrences:
208-
vobject_item = copy.copy(expanded_item.vobject_item)
208+
expanded: vobject.base.Component = copy.copy(expanded_item.vobject_item)
209+
is_expanded_filled: bool = False
209210

211+
for recurrence_dt in recurrences:
210212
recurrence_utc = recurrence_dt.astimezone(datetime.timezone.utc)
211213

212-
vevent = copy.deepcopy(vobject_item.vevent)
214+
vevent = copy.deepcopy(expanded.vevent)
213215
vevent.recurrence_id = ContentLine(
214216
name='RECURRENCE-ID',
215217
value=recurrence_utc.strftime('%Y%m%dT%H%M%SZ'), params={}
216218
)
217219

218-
if expanded is None:
219-
vobject_item.vevent = vevent
220-
expanded = vobject_item
220+
if is_expanded_filled is False:
221+
expanded.vevent = vevent
222+
is_expanded_filled = True
221223
else:
222224
expanded.add(vevent)
223225

radicale/tests/test_base.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -1526,6 +1526,7 @@ def test_report_sync_collection_invalid_sync_token(self) -> None:
15261526
assert not sync_token
15271527

15281528
def test_report_with_expand_property(self) -> None:
1529+
"""Test report with expand property"""
15291530
self.put("/calendar.ics/", get_file_content("event_daily_rrule.ics"))
15301531
req_body_without_expand = \
15311532
"""<?xml version="1.0" encoding="utf-8" ?>
@@ -1546,21 +1547,22 @@ def test_report_with_expand_property(self) -> None:
15461547
_, responses = self.report("/calendar.ics/", req_body_without_expand)
15471548
assert len(responses) == 1
15481549

1549-
response = responses['/calendar.ics/event_daily_rrule.ics']
1550-
status, element = list(response.values())[0]
1550+
response_without_expand = responses['/calendar.ics/event_daily_rrule.ics']
1551+
assert not isinstance(response_without_expand, int)
1552+
status, element = response_without_expand["C:calendar-data"]
15511553

1552-
assert status == 200
1554+
assert status == 200 and element.text
15531555

15541556
assert "RRULE" in element.text
15551557
assert "BEGIN:VTIMEZONE" in element.text
15561558
assert "RECURRENCE-ID" not in element.text
15571559

1558-
uids = []
1560+
uids: List[str] = []
15591561
for line in element.text.split("\n"):
15601562
if line.startswith("UID:"):
15611563
uid = line[len("UID:"):]
15621564
assert uid == "event_daily_rrule"
1563-
uids.append(uids)
1565+
uids.append(uid)
15641566

15651567
assert len(uids) == 1
15661568

@@ -1586,10 +1588,11 @@ def test_report_with_expand_property(self) -> None:
15861588

15871589
assert len(responses) == 1
15881590

1589-
response = responses['/calendar.ics/event_daily_rrule.ics']
1590-
status, element = list(response.values())[0]
1591+
response_with_expand = responses['/calendar.ics/event_daily_rrule.ics']
1592+
assert not isinstance(response_with_expand, int)
1593+
status, element = response_with_expand["C:calendar-data"]
15911594

1592-
assert status == 200
1595+
assert status == 200 and element.text
15931596
assert "RRULE" not in element.text
15941597
assert "BEGIN:VTIMEZONE" not in element.text
15951598

@@ -1598,7 +1601,7 @@ def test_report_with_expand_property(self) -> None:
15981601
for line in element.text.split("\n"):
15991602
if line.startswith("UID:"):
16001603
assert line == "UID:event_daily_rrule"
1601-
uids.append(uids)
1604+
uids.append(line)
16021605

16031606
if line.startswith("RECURRENCE-ID:"):
16041607
recurrence_ids.append(line)

0 commit comments

Comments
 (0)