Issue #3031130 by tim.plunkett: \Drupal\Core\KeyValueStore\MemoryStorage::rename() erases data if keys match

merge-requests/1222/merge
Alex Pott 2022-01-04 23:06:03 +00:00
parent c274b2b8f3
commit d70a475234
No known key found for this signature in database
GPG Key ID: BDA67E7EE836E5CE
2 changed files with 17 additions and 2 deletions

View File

@ -71,8 +71,10 @@ class MemoryStorage extends StorageBase {
* {@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]);
}
}
/**

View File

@ -189,6 +189,19 @@ abstract class StorageTestBase extends KernelTestBase {
$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.
*