diff --git a/core/lib/Drupal/Core/Flood/MemoryBackend.php b/core/lib/Drupal/Core/Flood/MemoryBackend.php index ddb42bc..52fa407 100644 --- a/core/lib/Drupal/Core/Flood/MemoryBackend.php +++ b/core/lib/Drupal/Core/Flood/MemoryBackend.php @@ -58,6 +58,9 @@ public function clear($name, $identifier = NULL) { * {@inheritdoc} */ public function isAllowed($name, $threshold, $window = 3600, $identifier = NULL) { + if (!isset($this->events[$name])) { + return $threshold > 0; + } if (!isset($identifier)) { $identifier = $this->requestStack->getCurrentRequest()->getClientIp(); } 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.