diff --git a/src/Symfony/Component/PropertyAccess/PropertyPathBuilder.php b/src/Symfony/Component/PropertyAccess/PropertyPathBuilder.php index ede9e6b3a538..b25d70b12e86 100644 --- a/src/Symfony/Component/PropertyAccess/PropertyPathBuilder.php +++ b/src/Symfony/Component/PropertyAccess/PropertyPathBuilder.php @@ -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; diff --git a/src/Symfony/Component/PropertyAccess/Tests/PropertyPathBuilderTest.php b/src/Symfony/Component/PropertyAccess/Tests/PropertyPathBuilderTest.php index 287b4b1f8361..3c02f4ded82e 100644 --- a/src/Symfony/Component/PropertyAccess/Tests/PropertyPathBuilderTest.php +++ b/src/Symfony/Component/PropertyAccess/Tests/PropertyPathBuilderTest.php @@ -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()); + } }