From 5e98f18bbf9aa294c7fdcb692900b53dae129780 Mon Sep 17 00:00:00 2001 From: Brian Matovu Date: Tue, 30 Mar 2021 11:11:56 +0300 Subject: [PATCH 1/2] Test unknown property from string fails --- tests/Recurr/Test/RuleTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/Recurr/Test/RuleTest.php b/tests/Recurr/Test/RuleTest.php index 3471f34..64e3e70 100644 --- a/tests/Recurr/Test/RuleTest.php +++ b/tests/Recurr/Test/RuleTest.php @@ -461,6 +461,14 @@ public function testBadWeekStart() { $this->rule->setWeekStart('monday'); } + + /** + * @expectedException \Recurr\Exception\InvalidRRule + */ + public function testUnknownPropertyFromStringThrowsException() + { + $this->rule->loadFromString('FREQ=MONTHLY;BYDAY=-1FR;COUNT=10;SKIP=2'); + } /** * @dataProvider exampleRruleProvider From a1c4760a9ec1317b3284301ff91337f01180e827 Mon Sep 17 00:00:00 2001 From: Brian Matovu Date: Tue, 30 Mar 2021 11:16:23 +0300 Subject: [PATCH 2/2] Validate unknown RRULE properties. --- src/Recurr/Rule.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/Recurr/Rule.php b/src/Recurr/Rule.php index dfcf40f..32224d0 100644 --- a/src/Recurr/Rule.php +++ b/src/Recurr/Rule.php @@ -174,6 +174,29 @@ class Rule /** @var array */ protected $exDates = array(); + + /** @var array */ + protected $properties = [ + 'FREQ', + 'DTSTART', + 'DTEND', + 'UNTIL', + 'UNTIL', + 'COUNT', + 'INTERVAL', + 'BYSECOND', + 'BYMINUTE', + 'BYHOUR', + 'BYDAY', + 'BYMONTHDAY', + 'BYYEARDAY', + 'BYWEEKNO', + 'BYMONTH', + 'BYSETPOS', + 'WKST', + 'RDATE', + 'EXDATE' + ]; /** * Construct a new Rule. @@ -431,6 +454,18 @@ public function loadFromArray($parts) if (isset($parts['EXDATE'])) { $this->setExDates(explode(',', $parts['EXDATE'])); } + + // UNKNOWN PROPERTIES + $invalidProperties = array_values(array_diff(array_keys($parts), $this->properties)); + + if($invalidProperties) { + $msg = array_pop($invalidProperties); + + if ($invalidProperties) + $msg = implode(', ', $invalidProperties).', and '.$msg; + + throw new InvalidRRule('Unknown RRULE property: '.$msg); + } return $this; }