Skip to content

Commit

Permalink
[PropertyAccess] Fixed PropertyPathBuilder remove that fails to reset…
Browse files Browse the repository at this point in the history
… internal indexes
  • Loading branch information
GregOriol authored and fabpot committed Mar 4, 2019
1 parent 4203bef commit 479dff4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/Symfony/Component/PropertyAccess/PropertyPathBuilder.php
Expand Up @@ -257,9 +257,8 @@ private function resize($offset, $cutLength, $insertionLength)
}

// All remaining elements should be removed
for (; $i < $length; ++$i) {
unset($this->elements[$i], $this->isIndex[$i]);
}
$this->elements = \array_slice($this->elements, 0, $i);
$this->isIndex = \array_slice($this->isIndex, 0, $i);
} else {
$diff = $insertionLength - $cutLength;

Expand Down
Expand Up @@ -285,4 +285,25 @@ public function testRemoveDoesNotAllowNegativeOffsets()
{
$this->builder->remove(-1);
}

public function testRemoveAndAppendAtTheEnd()
{
$this->builder->remove($this->builder->getLength() - 1);

$path = new PropertyPath('old1[old2].old3[old4][old5]');

$this->assertEquals($path, $this->builder->getPropertyPath());

$this->builder->appendProperty('old7');

$path = new PropertyPath('old1[old2].old3[old4][old5].old7');

$this->assertEquals($path, $this->builder->getPropertyPath());

$this->builder->remove($this->builder->getLength() - 1);

$path = new PropertyPath('old1[old2].old3[old4][old5]');

$this->assertEquals($path, $this->builder->getPropertyPath());
}
}

0 comments on commit 479dff4

Please sign in to comment.