[Pkg-owncloud-commits] [php-sabre-vobject] 13/19: BYSETPOS with values below -1 breaks and hangs.
David Prévot
taffit at moszumanska.debian.org
Tue May 19 20:10:13 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository php-sabre-vobject.
commit eb54a9646ba44d5fa24d8103dd87bc6c7caf7b57
Author: Evert Pot <me at evertpot.com>
Date: Fri Apr 10 17:37:22 2015 -0400
BYSETPOS with values below -1 breaks and hangs.
Fixes #212.
---
ChangeLog.md | 2 +
lib/Recur/RRuleIterator.php | 2 +-
.../Recur/EventIterator/ByMonthInDailyTest.php | 5 +-
.../Recur/EventIterator/BySetPosHangTest.php | 61 ++++++++++++++++++++++
4 files changed, 67 insertions(+), 3 deletions(-)
diff --git a/ChangeLog.md b/ChangeLog.md
index 3a78e03..b0d72bb 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -5,6 +5,8 @@ ChangeLog
------------------
* #219: Corrected validation of `EXDATE` properties with more than one value.
+* #212: `BYSETPOS` with values below `-1` was broken and could cause infinite
+ loops.
3.4.3 (2015-03-11)
diff --git a/lib/Recur/RRuleIterator.php b/lib/Recur/RRuleIterator.php
index 0cd1c03..41a96dc 100644
--- a/lib/Recur/RRuleIterator.php
+++ b/lib/Recur/RRuleIterator.php
@@ -840,7 +840,7 @@ class RRuleIterator implements Iterator {
foreach($this->bySetPos as $setPos) {
if ($setPos<0) {
- $setPos = count($result)-($setPos+1);
+ $setPos = count($result)+($setPos+1);
}
if (isset($result[$setPos-1])) {
$filteredResult[] = $result[$setPos-1];
diff --git a/tests/VObject/Recur/EventIterator/ByMonthInDailyTest.php b/tests/VObject/Recur/EventIterator/ByMonthInDailyTest.php
index 9c7d9b0..4f3f852 100644
--- a/tests/VObject/Recur/EventIterator/ByMonthInDailyTest.php
+++ b/tests/VObject/Recur/EventIterator/ByMonthInDailyTest.php
@@ -1,11 +1,12 @@
<?php
-namespace Sabre\VObject;
+namespace Sabre\VObject\Recur;
use
+ Sabre\VObject\Reader,
DateTime;
-class RecurrenceIteratorByMonthInDailyTest extends \PHPUnit_Framework_TestCase {
+class ByMonthInDailyTest extends \PHPUnit_Framework_TestCase {
/**
* This tests the expansion of dates with DAILY frequency in RRULE with BYMONTH restrictions
diff --git a/tests/VObject/Recur/EventIterator/BySetPosHangTest.php b/tests/VObject/Recur/EventIterator/BySetPosHangTest.php
new file mode 100644
index 0000000..bf346a5
--- /dev/null
+++ b/tests/VObject/Recur/EventIterator/BySetPosHangTest.php
@@ -0,0 +1,61 @@
+<?php
+
+namespace Sabre\VObject\Recur;
+
+use
+ Sabre\VObject\Reader,
+ DateTime;
+
+class BySetPosHangTest extends \PHPUnit_Framework_TestCase {
+
+ /**
+ * Using this iCalendar object, including BYSETPOS=-2 causes the iterator
+ * to hang, as reported in ticket #212.
+ *
+ * See: https://github.com/fruux/sabre-vobject/issues/212
+ */
+ function testExpand() {
+
+ $ics = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Sabre//Sabre VObject 3.4.2//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+SUMMARY:Test event 1
+DTSTART;TZID=Europe/Copenhagen:20150101T170000
+RRULE:FREQ=MONTHLY;BYDAY=TH;BYSETPOS=-2
+UID:b4071499-6fe4-418a-83b8-2b8d5ebb38e4
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+ $vcal = Reader::read($ics);
+ $this->assertInstanceOf('Sabre\\VObject\\Component\\VCalendar', $vcal);
+
+ $vcal->expand(new DateTime('2015-01-01'), new DateTime('2016-01-01'));
+
+ foreach ($vcal->VEVENT as $event) {
+ $dates[] = $event->DTSTART->getValue();
+ }
+
+ $expectedDates = array(
+ "20150101T160000Z",
+ "20150122T160000Z",
+ "20150219T160000Z",
+ "20150319T160000Z",
+ "20150423T150000Z",
+ "20150521T150000Z",
+ "20150618T150000Z",
+ "20150723T150000Z",
+ "20150820T150000Z",
+ "20150917T150000Z",
+ "20151022T150000Z",
+ "20151119T160000Z",
+ "20151224T160000Z",
+ );
+
+ $this->assertEquals($expectedDates, $dates);
+ }
+
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabre-vobject.git
More information about the Pkg-owncloud-commits
mailing list