Unverified Commit e1b059c3 authored by Alex Pott's avatar Alex Pott
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
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -71,9 +71,11 @@ public function setMultiple(array $data) {
   * {@inheritdoc}
   */
  public function rename($key, $new_key) {
    if ($key !== $new_key) {
      $this->data[$new_key] = $this->data[$key];
      unset($this->data[$key]);
    }
  }

  /**
   * {@inheritdoc}
+13 −0
Original line number Diff line number Diff line
@@ -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.
   *