Skip to content

Commit

Permalink
bug #30392 [PropertyAccess] Fixed PropertyPathBuilder remove that fai…
Browse files Browse the repository at this point in the history
…ls to reset internal indexes (GregOriol)

This PR was squashed before being merged into the 3.4 branch (closes #30392).

Discussion
----------

[PropertyAccess] Fixed PropertyPathBuilder remove that fails to reset internal indexes

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #30389
| License       | MIT
| Doc PR        | -

In addition to the fix (first commit), this PR adds \ to all not-yet-prefixed native functions in the PropertyPathBuilder (second commit).

NB: the behavior fixed here actually appeared in 2.2

Commits
-------

479dff4 [PropertyAccess] Fixed PropertyPathBuilder remove that fails to reset internal indexes
  • Loading branch information
fabpot committed Mar 4, 2019
2 parents 4203bef + 479dff4 commit 897ecb7
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 897ecb7

Please sign in to comment.