Skip to content

Commit c17b2cc

Browse files
committed
Fix HTTP error code on a free-busy-report with invalid range
Fixes #992.
1 parent 09ac4fd commit c17b2cc

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

lib/CalDAV/Xml/Request/FreeBusyQueryReport.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,18 @@ public static function xmlDeserialize(Reader $reader)
7575
if (!$start && !$end) {
7676
throw new BadRequest('The freebusy report must have a time-range element');
7777
}
78-
if ($start) {
79-
$start = DateTimeParser::parseDateTime($start);
80-
}
81-
if ($end) {
82-
$end = DateTimeParser::parseDateTime($end);
78+
79+
try {
80+
if ($start) {
81+
$start = DateTimeParser::parseDateTime($start);
82+
}
83+
if ($end) {
84+
$end = DateTimeParser::parseDateTime($end);
85+
}
86+
} catch (\Throwable $e) {
87+
throw new BadRequest($e->getMessage(), $e->getCode(), $e);
8388
}
89+
8490
$result = new self();
8591
$result->start = $start;
8692
$result->end = $end;

tests/Sabre/CalDAV/FreeBusyReportTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,19 @@ public function testFreeBusyReportNoACLPlugin()
155155
$report = $this->server->xml->parse($reportXML, null, $rootElem);
156156
$this->plugin->report($rootElem, $report, null);
157157
}
158+
159+
public function testFreeBusyReportInvalidTimeRange()
160+
{
161+
$reportXML = <<<XML
162+
<?xml version="1.0"?>
163+
<c:free-busy-query xmlns:c="urn:ietf:params:xml:ns:caldav">
164+
<c:time-range start="19900101" end="20400101"/>
165+
</c:free-busy-query>
166+
XML;
167+
$this->expectException(\Sabre\DAV\Exception\BadRequest::class);
168+
$this->expectExceptionMessage('The supplied iCalendar datetime value is incorrect: 19900101');
169+
170+
$report = $this->server->xml->parse($reportXML, null, $rootElem);
171+
$this->plugin->report($rootElem, $report, null);
172+
}
158173
}

0 commit comments

Comments
 (0)