Skip to content

Commit 7f5245c

Browse files
committed
bug symfony#17112 [PropertyAccess] Reorder elements array after PropertyPathBuilder::replace (alekitto)
This PR was merged into the 2.3 branch. Discussion ---------- [PropertyAccess] Reorder elements array after PropertyPathBuilder::replace | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#17102 | License | MIT | Doc PR | Commits ------- d0c0294 [PropertyAccess] Reorder elements array after PropertyPathBuilder::replace
2 parents d481dda + d0c0294 commit 7f5245c

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/Symfony/Component/PropertyAccess/PropertyPathBuilder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public function replace($offset, $length, $path, $pathOffset = 0, $pathLength =
142142
$this->elements[$offset + $i] = $path->getElement($pathOffset + $i);
143143
$this->isIndex[$offset + $i] = $path->isIndex($pathOffset + $i);
144144
}
145+
ksort($this->elements);
145146
}
146147

147148
/**

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,17 @@ public function testReplaceWithLongerPath()
252252
$this->assertEquals($path, $builder->getPropertyPath());
253253
}
254254

255+
public function testReplaceWithLongerPathKeepsOrder()
256+
{
257+
$path = new PropertyPath('new1.new2.new3');
258+
$expected = new PropertyPath('new1.new2.new3.old2');
259+
260+
$builder = new PropertyPathBuilder(new PropertyPath('old1.old2'));
261+
$builder->replace(0, 1, $path);
262+
263+
$this->assertEquals($expected, $builder->getPropertyPath());
264+
}
265+
255266
public function testRemove()
256267
{
257268
$this->builder->remove(3);

0 commit comments

Comments
 (0)