diff --git a/core/lib/Drupal/Core/Flood/MemoryBackend.php b/core/lib/Drupal/Core/Flood/MemoryBackend.php index ddb42bc..b80e7f2 100644 --- a/core/lib/Drupal/Core/Flood/MemoryBackend.php +++ b/core/lib/Drupal/Core/Flood/MemoryBackend.php @@ -61,6 +61,9 @@ public function isAllowed($name, $threshold, $window = 3600, $identifier = NULL) if (!isset($identifier)) { $identifier = $this->requestStack->getCurrentRequest()->getClientIp(); } + if (!isset($this->events[$name][$identifier])) { + return TRUE; + } $limit = microtime(TRUE) - $window; $number = count(array_filter($this->events[$name][$identifier], function ($timestamp) use ($limit) { return $timestamp > $limit; diff --git a/core/modules/system/src/Tests/System/FloodTest.php b/core/modules/system/src/Tests/System/FloodTest.php index a3a3368..bba3032 100644 --- a/core/modules/system/src/Tests/System/FloodTest.php +++ b/core/modules/system/src/Tests/System/FloodTest.php @@ -34,8 +34,9 @@ public function testCleanUp() { $window_expired = -1; $name = 'flood_test_cleanup'; - // Register expired event. $flood = \Drupal::flood(); + $this->assertTrue($flood->isAllowed($name, $threshold)); + // Register expired event. $flood->register($name, $window_expired); // Verify event is not allowed. $this->assertFalse($flood->isAllowed($name, $threshold)); @@ -62,6 +63,7 @@ public function testMemoryBackend() { $request_stack = \Drupal::service('request_stack'); $flood = new MemoryBackend($request_stack); + $this->assertTrue($flood->isAllowed($name, $threshold)); // Register expired event. $flood->register($name, $window_expired); // Verify event is not allowed. @@ -90,6 +92,7 @@ public function testDatabaseBackend() { $connection = \Drupal::service('database'); $request_stack = \Drupal::service('request_stack'); $flood = new DatabaseBackend($connection, $request_stack); + $this->assertTrue($flood->isAllowed($name, $threshold)); // Register expired event. $flood->register($name, $window_expired); // Verify event is not allowed.