Skip to content

Commit

Permalink
Merge pull request #1319 from PhilZ-cwm6/master_20210109_patch_php74_…
Browse files Browse the repository at this point in the history
…null_check

Properly fix "Trying to access array offset on value of type bool"
  • Loading branch information
phil-davis authored Jan 11, 2021
2 parents d385f9b + 9d29581 commit 0e9a119
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 7 deletions.
10 changes: 6 additions & 4 deletions lib/CalDAV/Backend/PDO.php
Original file line number Diff line number Diff line change
Expand Up @@ -789,8 +789,10 @@ public function calendarQuery($calendarId, array $filters)

// If start time OR the end time is not specified, we can do a
// 100% accurate mysql query.
if (!$filters['prop-filters'] && !$filters['comp-filters'][0]['comp-filters'] && !$filters['comp-filters'][0]['prop-filters'] && (!$timeRange['start'] || !$timeRange['end'])) {
$requirePostFilter = false;
if (!$filters['prop-filters'] && !$filters['comp-filters'][0]['comp-filters'] && !$filters['comp-filters'][0]['prop-filters'] && $timeRange) {
if ((array_key_exists('start', $timeRange) && !$timeRange['start']) || (array_key_exists('end', $timeRange) && !$timeRange['end'])) {
$requirePostFilter = false;
}
}
}
}
Expand All @@ -810,11 +812,11 @@ public function calendarQuery($calendarId, array $filters)
$values['componenttype'] = $componentType;
}

if ($timeRange && $timeRange['start']) {
if ($timeRange && array_key_exists('start', $timeRange) && $timeRange['start']) {
$query .= ' AND lastoccurence > :startdate';
$values['startdate'] = $timeRange['start']->getTimeStamp();
}
if ($timeRange && $timeRange['end']) {
if ($timeRange && array_key_exists('end', $timeRange) && $timeRange['end']) {
$query .= ' AND firstoccurence < :enddate';
$values['enddate'] = $timeRange['end']->getTimeStamp();
}
Expand Down
20 changes: 18 additions & 2 deletions lib/CalDAV/CalendarQueryValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,15 @@ protected function validateCompFilters(VObject\Component $parent, array $filters

if ($filter['time-range']) {
foreach ($parent->{$filter['name']} as $subComponent) {
if ($this->validateTimeRange($subComponent, $filter['time-range']['start'], $filter['time-range']['end'])) {
$start = null;
$end = null;
if (array_key_exists('start', $filter['time-range'])) {
$start = $filter['time-range']['start'];
}
if (array_key_exists('end', $filter['time-range'])) {
$end = $filter['time-range']['end'];
}
if ($this->validateTimeRange($subComponent, $start, $end)) {
continue 2;
}
}
Expand Down Expand Up @@ -130,7 +138,15 @@ protected function validatePropFilters(VObject\Component $parent, array $filters

if ($filter['time-range']) {
foreach ($parent->{$filter['name']} as $subComponent) {
if ($this->validateTimeRange($subComponent, $filter['time-range']['start'], $filter['time-range']['end'])) {
$start = null;
$end = null;
if (array_key_exists('start', $filter['time-range'])) {
$start = $filter['time-range']['start'];
}
if (array_key_exists('end', $filter['time-range'])) {
$end = $filter['time-range']['end'];
}
if ($this->validateTimeRange($subComponent, $start, $end)) {
continue 2;
}
}
Expand Down
90 changes: 89 additions & 1 deletion tests/Sabre/CalDAV/Backend/AbstractPDOTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ public function testCalendarQueryTimeRange()
], $backend->calendarQuery([1, 1], $filters));
}

public function testCalendarQueryTimeRangeNoEnd()
public function testCalendarQueryTimeRangeEndNull()
{
$backend = new PDO($this->pdo);
$backend->createCalendarObject([1, 1], 'todo', "BEGIN:VCALENDAR\r\nBEGIN:VTODO\r\nEND:VTODO\r\nEND:VCALENDAR\r\n");
Expand Down Expand Up @@ -811,6 +811,94 @@ public function testCalendarQueryTimeRangeNoEnd()
], $backend->calendarQuery([1, 1], $filters));
}

public function testCalendarQueryTimeRangeNoEnd()
{
$backend = new PDO($this->pdo);
$backend->createCalendarObject([1, 1], 'todo', "BEGIN:VCALENDAR\r\nBEGIN:VTODO\r\nEND:VTODO\r\nEND:VCALENDAR\r\n");
$backend->createCalendarObject([1, 1], 'event', "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART:20120101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
$backend->createCalendarObject([1, 1], 'event2', "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART:20120103\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");

$filters = [
'name' => 'VCALENDAR',
'comp-filters' => [
[
'name' => 'VEVENT',
'comp-filters' => [],
'prop-filters' => [],
'is-not-defined' => false,
'time-range' => [
'start' => new \DateTime('20120102'),
],
],
],
'prop-filters' => [],
'is-not-defined' => false,
'time-range' => null,
];

$this->assertEquals([
'event2',
], $backend->calendarQuery([1, 1], $filters));
}

public function testCalendarQueryTimeRangeNoStart()
{
$backend = new PDO($this->pdo);
$backend->createCalendarObject([1, 1], 'todo', "BEGIN:VCALENDAR\r\nBEGIN:VTODO\r\nEND:VTODO\r\nEND:VCALENDAR\r\n");
$backend->createCalendarObject([1, 1], 'event', "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART:20120101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
$backend->createCalendarObject([1, 1], 'event2', "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART:20120103\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");

$filters = [
'name' => 'VCALENDAR',
'comp-filters' => [
[
'name' => 'VEVENT',
'comp-filters' => [],
'prop-filters' => [],
'is-not-defined' => false,
'time-range' => [
'end' => new \DateTime('20120102'),
],
],
],
'prop-filters' => [],
'is-not-defined' => false,
'time-range' => null,
];

$this->assertEquals([
'event',
], $backend->calendarQuery([1, 1], $filters));
}

public function testCalendarQueryTimeRangeNotSpecified()
{
$backend = new PDO($this->pdo);
$backend->createCalendarObject([1, 1], 'todo', "BEGIN:VCALENDAR\r\nBEGIN:VTODO\r\nEND:VTODO\r\nEND:VCALENDAR\r\n");
$backend->createCalendarObject([1, 1], 'event', "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART:20120101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
$backend->createCalendarObject([1, 1], 'event2', "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART:20120103\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");

$filters = [
'name' => 'VCALENDAR',
'comp-filters' => [
[
'name' => 'VEVENT',
'comp-filters' => [],
'prop-filters' => [],
'is-not-defined' => false,
'time-range' => false,
],
],
'prop-filters' => [],
'is-not-defined' => false,
'time-range' => null,
];

$result = $backend->calendarQuery([1, 1], $filters);
$this->assertTrue(in_array('event', $result));
$this->assertTrue(in_array('event2', $result));
}

public function testGetChanges()
{
$backend = new PDO($this->pdo);
Expand Down

0 comments on commit 0e9a119

Please sign in to comment.