From dbcff3eb2766ca7ae57fa463f74c61a7a5457743 Mon Sep 17 00:00:00 2001 From: rlanvin Date: Fri, 11 Nov 2016 20:20:09 +0200 Subject: [PATCH] Fix a undefined index error in the RFC parser --- src/RRule.php | 6 +++++- tests/RRuleTest.php | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/RRule.php b/src/RRule.php index 4827cf7..236d144 100755 --- a/src/RRule.php +++ b/src/RRule.php @@ -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( diff --git a/tests/RRuleTest.php b/tests/RRuleTest.php index 5c218c2..000de17 100755 --- a/tests/RRuleTest.php +++ b/tests/RRuleTest.php @@ -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'),