diff --git a/core/lib/Drupal/Core/KeyValueStore/MemoryStorage.php b/core/lib/Drupal/Core/KeyValueStore/MemoryStorage.php index d6a6ca91d40924d578fd63b199b77841c451ccd6..38c62685df70cef4f3c082306f602e5d2fc0086d 100644 --- a/core/lib/Drupal/Core/KeyValueStore/MemoryStorage.php +++ b/core/lib/Drupal/Core/KeyValueStore/MemoryStorage.php @@ -71,8 +71,10 @@ public function setMultiple(array $data) { * {@inheritdoc} */ public function rename($key, $new_key) { - $this->data[$new_key] = $this->data[$key]; - unset($this->data[$key]); + if ($key !== $new_key) { + $this->data[$new_key] = $this->data[$key]; + unset($this->data[$key]); + } } /** diff --git a/core/tests/Drupal/KernelTests/Core/KeyValueStore/StorageTestBase.php b/core/tests/Drupal/KernelTests/Core/KeyValueStore/StorageTestBase.php index a79e0232b1f71cac842abb53ccd78d0fd328deb9..23059b8372bed9b984404f4ce2a86a41ed987f0e 100644 --- a/core/tests/Drupal/KernelTests/Core/KeyValueStore/StorageTestBase.php +++ b/core/tests/Drupal/KernelTests/Core/KeyValueStore/StorageTestBase.php @@ -189,6 +189,19 @@ public function testRename() { $this->assertNull($store->get('old')); } + /** + * Tests the rename operation. + */ + public function testRenameNoChange() { + $stores = $this->createStorage(); + $store = $stores[0]; + + $store->set('old', 'thing'); + $this->assertSame($store->get('old'), 'thing'); + $store->rename('old', 'old'); + $this->assertSame($store->get('old'), 'thing'); + } + /** * Creates storage objects for each collection defined for this class. *