From 3473e7c2b11682082ab191fb7319181b3a298047 Mon Sep 17 00:00:00 2001 From: Mathieu Rochette Date: Fri, 11 Oct 2024 17:00:18 +0200 Subject: [PATCH 1/2] Throw InvalidDataException when RRule is invalid --- lib/Property/ICalendar/Recur.php | 9 ++++++++- tests/VObject/Property/ICalendar/RecurTest.php | 11 +++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/Property/ICalendar/Recur.php b/lib/Property/ICalendar/Recur.php index 9a1e9e643..10081673e 100644 --- a/lib/Property/ICalendar/Recur.php +++ b/lib/Property/ICalendar/Recur.php @@ -189,7 +189,14 @@ public static function stringToArray(string $value): array if (empty($part)) { continue; } - list($partName, $partValue) = explode('=', $part); + + $parts = explode('=', $part); + + if (2 !== count($parts)) { + throw new InvalidDataException('The supplied iCalendar RRULE part is incorrect: '.$part); + } + + list($partName, $partValue) = $parts; // The value itself had multiple values.. if (false !== strpos($partValue, ',')) { diff --git a/tests/VObject/Property/ICalendar/RecurTest.php b/tests/VObject/Property/ICalendar/RecurTest.php index b2750f03b..0adf30215 100644 --- a/tests/VObject/Property/ICalendar/RecurTest.php +++ b/tests/VObject/Property/ICalendar/RecurTest.php @@ -4,6 +4,7 @@ use PHPUnit\Framework\TestCase; use Sabre\VObject\Component\VCalendar; +use Sabre\VObject\InvalidDataException; use Sabre\VObject\Node; use Sabre\VObject\Reader; @@ -194,6 +195,16 @@ public function testValidateStripNoFreq(): void ); } + public function testUnrepairableRRule(): void + { + $calendar = new VCalendar(); + $property = $calendar->createProperty('RRULE', 'IAmNotARRule'); + + $this->expectException(InvalidDataException::class); + + $property->validate(Node::REPAIR); + } + public function testValidateInvalidByMonthRruleWithRepair(): void { $calendar = new VCalendar(); From ab14f5e937e5f39137a6854d764a9808caaf3de2 Mon Sep 17 00:00:00 2001 From: Mathieu Rochette Date: Fri, 11 Oct 2024 17:13:32 +0200 Subject: [PATCH 2/2] fixup: fix test --- tests/VObject/Property/ICalendar/RecurTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/VObject/Property/ICalendar/RecurTest.php b/tests/VObject/Property/ICalendar/RecurTest.php index 0adf30215..99d2525c6 100644 --- a/tests/VObject/Property/ICalendar/RecurTest.php +++ b/tests/VObject/Property/ICalendar/RecurTest.php @@ -197,11 +197,9 @@ public function testValidateStripNoFreq(): void public function testUnrepairableRRule(): void { + $this->expectException(InvalidDataException::class); $calendar = new VCalendar(); $property = $calendar->createProperty('RRULE', 'IAmNotARRule'); - - $this->expectException(InvalidDataException::class); - $property->validate(Node::REPAIR); }