Unverified Commit e1b059c3 authored by alexpott's avatar alexpott
Browse files

Issue #3031130 by tim.plunkett:...

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

(cherry picked from commit d70a4752)
parent 5b6ee132
......@@ -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]);
}
}
/**
......
......@@ -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.
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment