8000 [PropertyAccess] Fixed PropertyPathBuilder remove that fails to reset… · symfony/symfony@479dff4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 479dff4

Browse files
GregOriolfabpot
authored andcommitted
[PropertyAccess] Fixed PropertyPathBuilder remove that fails to reset internal indexes
1 parent 4203bef commit 479dff4

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/Symfony/Component/PropertyAccess/PropertyPathBuilder.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,8 @@ private function resize($offset, $cutLength, $insertionLength)
257257
}
258258

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

src/Symfony/Component/PropertyAccess/Tests/PropertyPathBuilderTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,4 +285,25 @@ public function testRemoveDoesNotAllowNegativeOffsets()
285285
{
286286
$this->builder->remove(-1);
287287
}
288+
289+
public function testRemoveAndAppendAtTheEnd()
290+
{
291+
$this->builder->remove($this->builder->getLength() - 1);
292+
293+
$path = new PropertyPath('old1[old2].old3[old4][old5]');
294+
295+
$this->assertEquals($path, $this->builder->getPropertyPath());
296+
297+
$this->builder->appendProperty('old7');
298+
299+
$path = new PropertyPath('old1[old2].old3[old4][old5].old7');
300+
301+
$this->assertEquals($path, $this->builder->getPropertyPath());
302+
303+
$this->builder->remove($this->builder->getLength() - 1);
304+
305+
$path = new PropertyPath('old1[old2].old3[old4][old5]');
306+
307+
$this->assertEquals($path, $this->builder->getPropertyPath());
308+
}
288309
}

0 commit comments

Comments
 (0)
0