Skip to content

Commit

Permalink
Merge pull request #44017 from rcwschaller/fix/caldav/eventcomparisio…
Browse files Browse the repository at this point in the history
…nservice-uses-wrong-array-comparison
  • Loading branch information
skjnldsv authored Mar 26, 2024
2 parents 0c941d3 + fa6e613 commit 47ac907
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
2 changes: 1 addition & 1 deletion apps/dav/lib/CalDAV/EventComparisonService.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private function removeIfUnchanged(VEvent $filterEvent, array &$eventsToFilter):
$eventToFilterData[] = IMipService::readPropertyWithDefault($eventToFilter, $eventDiff, '');
}
// events are identical and can be removed
if (empty(array_diff($filterEventData, $eventToFilterData))) {
if ($filterEventData === $eventToFilterData) {
unset($eventsToFilter[$k]);
return true;
}
Expand Down
67 changes: 67 additions & 0 deletions apps/dav/tests/unit/CalDAV/EventComparisonServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

/**
* @copyright 2023 Daniel Kesselberg <mail@danielkesselberg.de>
* @copyright 2024 Robert C. Schaller <gtbc_robert.schaller@rsxc.de>
*
* @author 2023 Daniel Kesselberg <mail@danielkesselberg.de>
*
Expand Down Expand Up @@ -137,4 +138,70 @@ public function testModifiedUnmodifiedEvent(): void {
$this->assertEquals([$vEventOld2], $result['old']);
$this->assertEquals([$vEventNew2], $result['new']);
}

// First test to certify fix for issue nextcloud/server#41084
public function testSequenceNumberIncrementDetectedForFirstModificationToEventWithoutZeroInit(): void {
$vCalendarOld = new VCalendar();
$vCalendarNew = new VCalendar();

$vEventOld = $vCalendarOld->add('VEVENT', [
'UID' => 'uid-1234',
'LAST-MODIFIED' => 123456,
// 'SEQUENCE' => 0, // sequence number may not be set to zero during event creation and instead fully omitted
'SUMMARY' => 'Fellowship meeting',
'DTSTART' => new \DateTime('2016-01-01 00:00:00'),
'RRULE' => 'FREQ=DAILY;INTERVAL=1;UNTIL=20160201T000000Z',
]);
$vEventOld->add('ORGANIZER', 'mailto:gandalf@wiz.ard');
$vEventOld->add('ATTENDEE', 'mailto:' . 'frodo@hobb.it', ['RSVP' => 'TRUE', 'CN' => 'Frodo']);

$vEventNew = $vCalendarNew->add('VEVENT', [
'UID' => 'uid-1234',
'LAST-MODIFIED' => 123456,
'SEQUENCE' => 1,
'SUMMARY' => 'Fellowship meeting',
'DTSTART' => new \DateTime('2016-01-01 00:00:00'),
'RRULE' => 'FREQ=DAILY;INTERVAL=1;UNTIL=20160201T000000Z',
]);
$vEventNew->add('ORGANIZER', 'mailto:gandalf@wiz.ard');
$vEventNew->add('ATTENDEE', 'mailto:' . 'frodo@hobb.it', ['RSVP' => 'TRUE', 'CN' => 'Frodo']);

$result = $this->eventComparisonService->findModified($vCalendarNew, $vCalendarOld);
$this->assertEquals([$vEventOld], $result['old']);
$this->assertEquals([$vEventNew], $result['new']);
}

// Second test to certify fix for issue nextcloud/server#41084
public function testSequenceNumberIncrementDetectedForFirstModificationToEventWithZeroInit(): void {
$vCalendarOld = new VCalendar();
$vCalendarNew = new VCalendar();

$vEventOld = $vCalendarOld->add('VEVENT', [
'UID' => 'uid-1234',
'LAST-MODIFIED' => 123456,
'SEQUENCE' => 0,
'SUMMARY' => 'Fellowship meeting',
'DTSTART' => new \DateTime('2016-01-01 00:00:00'),
'RRULE' => 'FREQ=DAILY;INTERVAL=1;UNTIL=20160201T000000Z',
]);
$vEventOld->add('ORGANIZER', 'mailto:gandalf@wiz.ard');
$vEventOld->add('ATTENDEE', 'mailto:' . 'frodo@hobb.it', ['RSVP' => 'TRUE', 'CN' => 'Frodo']);

$vEventNew = $vCalendarNew->add('VEVENT', [
'UID' => 'uid-1234',
'LAST-MODIFIED' => 123456,
'SEQUENCE' => 1,
'SUMMARY' => 'Fellowship meeting',
'DTSTART' => new \DateTime('2016-01-01 00:00:00'),
'RRULE' => 'FREQ=DAILY;INTERVAL=1;UNTIL=20160201T000000Z',
]);
$vEventNew->add('ORGANIZER', 'mailto:gandalf@wiz.ard');
$vEventNew->add('ATTENDEE', 'mailto:' . 'frodo@hobb.it', ['RSVP' => 'TRUE', 'CN' => 'Frodo']);

$result = $this->eventComparisonService->findModified($vCalendarNew, $vCalendarOld);
$this->assertEquals([$vEventOld], $result['old']);
$this->assertEquals([$vEventNew], $result['new']);
}


}

0 comments on commit 47ac907

Please sign in to comment.