1
0
mirror of https://github.com/rlanvin/php-rrule.git synced 2025-02-20 09:54:16 +01:00

Fix a undefined index error in the RFC parser

This commit is contained in:
rlanvin 2016-11-11 20:20:09 +02:00
parent 9b8986b954
commit dbcff3eb27
2 changed files with 28 additions and 1 deletions

View File

@ -706,7 +706,11 @@ class RRule implements RRuleInterface
break;
case 'RRULE':
foreach ( explode(';',$property_value) as $pair ) {
list($key, $value) = explode('=', $pair);
$pair = explode('=', $pair);
if ( ! isset($pair[1]) || isset($pair[2]) ) {
throw new \InvalidArgumentException("Failed to parse RFC string, malformed RRULE property: $property_value");
}
list($key, $value) = $pair;
if ( $key === 'UNTIL' ) {
if ( ! preg_match($rfc_date_regexp, $value) ) {
throw new \InvalidArgumentException(

View File

@ -65,6 +65,25 @@ class RRuleTest extends PHPUnit_Framework_TestCase
new RRule($rule);
}
/**
* These rules are valid according to the RFC, just making sure that the lib doesn't reject them.
*/
public function validRules()
{
return array(
// The BYMONTHDAY rule part MUST NOT be specified when the FREQ rule part is set to WEEKLY.
array(array('FREQ' => 'WEEKLY', 'BYMONTHDAY' => array()))
);
}
/**
* @dataProvider validRules
*/
public function testValidRules($rule)
{
new RRule($rule);
}
/**
* YEARLY rules, mostly taken from Python test suite.
*/
@ -1748,6 +1767,10 @@ class RRuleTest extends PHPUnit_Framework_TestCase
public function invalidRfcStrings()
{
return array(
// plain invalid strings
array('foobar'),
array('blah=blah=blah'),
// test invalid date formats
array('DTSTART:2006-06-24
RRULE:FREQ=DAILY'),