Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate unknown RRULE properties #187

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/Recurr/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 8 additions & 0 deletions tests/Recurr/Test/RuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down