diff --git a/core/lib/Drupal/Core/KeyValueStore/DatabaseStorage.php b/core/lib/Drupal/Core/KeyValueStore/DatabaseStorage.php index 569d807..789f626 100644 --- a/core/lib/Drupal/Core/KeyValueStore/DatabaseStorage.php +++ b/core/lib/Drupal/Core/KeyValueStore/DatabaseStorage.php @@ -78,6 +78,10 @@ public function has($key) { * {@inheritdoc} */ public function getMultiple(array $keys) { + if (empty($keys)) { + return []; + } + $values = array(); try { $result = $this->connection->query('SELECT name, value FROM {' . $this->connection->escapeTable($this->table) . '} WHERE name IN ( :keys[] ) AND collection = :collection', array(':keys[]' => $keys, ':collection' => $this->collection))->fetchAllAssoc('name'); diff --git a/core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php b/core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php index 2db6aab..99d970f 100644 --- a/core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php +++ b/core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php @@ -51,6 +51,10 @@ public function has($key) { * {@inheritdoc} */ public function getMultiple(array $keys) { + if (empty($keys)) { + return []; + } + try { $values = $this->connection->query( 'SELECT name, value FROM {' . $this->connection->escapeTable($this->table) . '} WHERE expire > :now AND name IN ( :keys[] ) AND collection = :collection', diff --git a/core/tests/Drupal/KernelTests/Core/KeyValueStore/StorageTestBase.php b/core/tests/Drupal/KernelTests/Core/KeyValueStore/StorageTestBase.php index 48e047d..6b84ee7 100644 --- a/core/tests/Drupal/KernelTests/Core/KeyValueStore/StorageTestBase.php +++ b/core/tests/Drupal/KernelTests/Core/KeyValueStore/StorageTestBase.php @@ -94,6 +94,11 @@ public function testCRUD() { $this->assertIdenticalObject($value, $result[$j]); } + // Verify that passing in an empty list of keys, returns an empty + // array. + $result = $stores[0]->getMultiple([]); + $this->assertEquals([], $result); + // Verify that the other collection was not affected. $this->assertFalse($stores[1]->get('foo')); $this->assertFalse($stores[1]->get('bar'));