Skip to content

Commit

Permalink
Merge pull request #696 from phil-davis/rrule-invalid-4.5
Browse files Browse the repository at this point in the history
[4.5] Throw InvalidDataException when RRule is invalid
  • Loading branch information
phil-davis authored Oct 14, 2024
2 parents 7044047 + 8b3e5d2 commit 72ec4ce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/Property/ICalendar/Recur.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Sabre\VObject\Property\ICalendar;

use Sabre\VObject\InvalidDataException;
use Sabre\VObject\Property;
use Sabre\Xml;

Expand Down Expand Up @@ -198,7 +199,14 @@ public static function stringToArray($value)
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, ',')) {
Expand Down
9 changes: 9 additions & 0 deletions tests/VObject/Property/ICalendar/RecurTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -194,6 +195,14 @@ public function testValidateStripNoFreq()
);
}

public function testUnrepairableRRule()
{
$this->expectException(InvalidDataException::class);
$calendar = new VCalendar();
$property = $calendar->createProperty('RRULE', 'IAmNotARRule');
$property->validate(Node::REPAIR);
}

public function testValidateInvalidByMonthRruleWithRepair()
{
$calendar = new VCalendar();
Expand Down

0 comments on commit 72ec4ce

Please sign in to comment.