Skip to content

Commit

Permalink
fixes issue sabre-io#329 (Endless loop in RRuleIterator if BYMONTHDAY…
Browse files Browse the repository at this point in the history
… does not exist in BYMONTH)
  • Loading branch information
PHPGangsta committed Jul 14, 2016
1 parent f812114 commit ae75a4f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/Recur/RRuleIterator.php
Expand Up @@ -588,6 +588,11 @@ protected function nextYearly() {
(int)$currentDayOfMonth
);

// maximum year 10000 should be safe to stop (2016 + max 3500 yearly occurrences)
if ((int)$currentYear > 10000) {
throw new NoInstancesException('This recurrence rule does not generate any valid instances, stopped in year 10000');
}

}

// If we made it here, it means we got a valid occurrence
Expand Down
32 changes: 31 additions & 1 deletion tests/VObject/Recur/RRuleIteratorTest.php
Expand Up @@ -275,7 +275,7 @@ function testMonthly() {

}

function testMonlthyEndOfMonth() {
function testMonthlyEndOfMonth() {

$this->parse(
'FREQ=MONTHLY;INTERVAL=2;COUNT=12',
Expand Down Expand Up @@ -458,6 +458,36 @@ function testYearlyByMonthByDay() {

}

/**
* There is no November 31st, the endless loop should be stopped by an Exception
*
* @expectedException \Sabre\VObject\Recur\NoInstancesException
*/
function testYearlyByMonthByMonthDayNotExistingDay() {

$this->parse(
'FREQ=YEARLY;COUNT=6;BYMONTH=11;BYMONTHDAY=31',
'2011-04-04 00:00:00',
[]
);

}

/**
* There is no February 29th in odd years, the endless loop should be stopped by an Exception
*
* @expectedException \Sabre\VObject\Recur\NoInstancesException
*/
function testYearlyLeapYearsInOddYears() {

$this->parse(
'FREQ=YEARLY;INTERVAL=2;COUNT=6;BYMONTH=2;BYMONTHDAY=29',
'2011-02-29 00:00:00',
[]
);

}

function testFastForward() {

// The idea is that we're fast-forwarding too far in the future, so
Expand Down

0 comments on commit ae75a4f

Please sign in to comment.