[Pkg-owncloud-commits] [php-sabre-vobject] 05/29: Moved $maxInstances to Settings::$maxRecurrences.

David Prévot taffit at moszumanska.debian.org
Sat Dec 12 19:26:57 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 1a6c843fe8f1598f8f4ca2971b176d3acf707747
Author: Evert Pot <me at evertpot.com>
Date:   Wed Dec 2 14:14:41 2015 -0500

    Moved $maxInstances to Settings::$maxRecurrences.
    
    Fixes #272
---
 lib/FreeBusyGenerator.php                            |  2 +-
 lib/Recur/EventIterator.php                          | 20 +++-----------------
 lib/Settings.php                                     | 17 +++++++++++++++++
 .../VObject/Recur/EventIterator/MaxInstancesTest.php |  8 ++++----
 4 files changed, 25 insertions(+), 22 deletions(-)

diff --git a/lib/FreeBusyGenerator.php b/lib/FreeBusyGenerator.php
index 88b63eb..adc2b7a 100644
--- a/lib/FreeBusyGenerator.php
+++ b/lib/FreeBusyGenerator.php
@@ -437,7 +437,7 @@ class FreeBusyGenerator {
                                 $iterator->fastForward($this->start);
                             }
 
-                            $maxRecurrences = 200;
+                            $maxRecurrences = Settings::$maxRecurrences;
 
                             while ($iterator->valid() && --$maxRecurrences) {
 
diff --git a/lib/Recur/EventIterator.php b/lib/Recur/EventIterator.php
index ca477f0..baf57d2 100644
--- a/lib/Recur/EventIterator.php
+++ b/lib/Recur/EventIterator.php
@@ -8,6 +8,7 @@ use DateTimeInterface;
 use InvalidArgumentException;
 use Sabre\VObject\Component;
 use Sabre\VObject\Component\VEvent;
+use Sabre\VObject\Settings;
 
 /**
  * This class is used to determine new for a recurring event, when the next
@@ -71,21 +72,6 @@ class EventIterator implements \Iterator {
      */
     protected $allDay = false;
 
-
-    /**
-     * Automatically stop iterating after this many iterations.
-     *
-     * This is a security measure. Without this, it would be possible to craft
-     * specific events that recur many, many times, potentially DDOSing the
-     * server.
-     *
-     * The default (3500) allows creation of a dialy event that goes on for 10
-     * years, which is hopefully long enouogh for most.
-     *
-     * Set this value to -1 to disable this control altogether.
-     */
-    static $maxInstances = 3500;
-
     /**
      * Creates the iterator.
      *
@@ -329,8 +315,8 @@ class EventIterator implements \Iterator {
      */
     function valid() {
 
-        if ($this->counter > self::$maxInstances && self::$maxInstances !== -1) {
-            throw new MaxInstancesExceededException('Recurring events are only allowed to generate ' . self::$maxInstances);
+        if ($this->counter > Settings::$maxRecurrences && Settings::$maxRecurrences !== -1) {
+            throw new MaxInstancesExceededException('Recurring events are only allowed to generate ' . Settings::$maxRecurrences);
         }
         return !!$this->currentDate;
 
diff --git a/lib/Settings.php b/lib/Settings.php
index 53acd5e..92b7010 100644
--- a/lib/Settings.php
+++ b/lib/Settings.php
@@ -36,4 +36,21 @@ class Settings {
      */
     static $maxDate = '2100-01-01';
 
+    /**
+     * The maximum number of recurrences that will be generated.
+     *
+     * This setting limits the maximum of recurring events that this library
+     * generates in its recurrence iterators.
+     *
+     * This is a security measure. Without this, it would be possible to craft
+     * specific events that recur many, many times, potentially DDOSing the
+     * server.
+     *
+     * The default (3500) allows creation of a dialy event that goes on for 10
+     * years, which is hopefully long enough for most.
+     *
+     * Set this value to -1 to disable this control altogether.
+     */
+    static $maxRecurrences = 3500;
+
 }
diff --git a/tests/VObject/Recur/EventIterator/MaxInstancesTest.php b/tests/VObject/Recur/EventIterator/MaxInstancesTest.php
index cd38aad..21a3f40 100644
--- a/tests/VObject/Recur/EventIterator/MaxInstancesTest.php
+++ b/tests/VObject/Recur/EventIterator/MaxInstancesTest.php
@@ -3,7 +3,7 @@
 namespace Sabre\VObject\Recur\EventIterator;
 
 use Sabre\VObject\Reader;
-use Sabre\VObject\Recur\EventIterator;
+use Sabre\VObject\Settings;
 use Sabre\VObject\TestCase;
 use DateTime;
 
@@ -26,15 +26,15 @@ END:VEVENT
 END:VCALENDAR
 ICS;
 
-        $temp = EventIterator::$maxInstances;
-        EventIterator::$maxInstances = 4;
+        $temp = Settings::$maxRecurrences;
+        Settings::$maxRecurrences = 4;
         try {
 
             $vcal = Reader::read($input);
             $vcal->expand(new DateTime('2014-08-01'), new DateTime('2014-09-01'));
 
         } finally {
-            EventIterator::$maxInstances = $temp;
+            Settings::$maxRecurrences = $temp;
         }
 
     }

-- 
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