Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5cb8312

Browse files
haase-fabianfabpot
authored andcommitted
[PropertyAccess] Fix Regression in PropertyAccessor::isWritable()
1 parent 75ace35 commit 5cb8312

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/Symfony/Component/PropertyAccess/PropertyAccessor.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,8 @@ public function isWritable($objectOrArray, $propertyPath)
313313
if (!$zval[self::VALUE] instanceof \ArrayAccess && !\is_array($zval[self::VALUE])) {
314314
return false;
315315
}
316-
} else {
317-
if (!$this->isPropertyWritable($zval[self::VALUE], $propertyPath->getElement($i))) {
318-
return false;
319-
}
316+
} elseif (!\is_object($zval[self::VALUE]) || !$this->isPropertyWritable($zval[self::VALUE], $propertyPath->getElement($i))) {
317+
return false;
320318
}
321319

322320
if (\is_object($zval[self::VALUE])) {
@@ -663,10 +661,6 @@ private function getWriteInfo(string $class, string $property, $value): Property
663661
*/
664662
private function isPropertyWritable(object $object, string $property): bool
665663
{
666-
if (!\is_object($object)) {
667-
return false;
668-
}
669-
670664
$mutatorForArray = $this->getWriteInfo(\get_class($object), $property, []);
671665

672666
if (PropertyWriteInfo::TYPE_NONE !== $mutatorForArray->getType() || ($object instanceof \stdClass && property_exists($object, $property))) {

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ public function getValidPropertyPaths()
3838
];
3939
}
4040

41+
public function getInvalidPropertyPaths()
42+
{
43+
return [
44+
[$this->getContainer(['firstName' => 'Bernhard']), 'firstName', 'Bernhard'],
45+
[$this->getContainer(['person' => $this->getContainer(['firstName' => 'Bernhard'])]), 'person.firstName', 'Bernhard'],
46+
];
47+
}
48+
4149
/**
4250
* @dataProvider getValidPropertyPaths
4351
*/
@@ -83,4 +91,12 @@ public function testIsWritable($collection, $path)
8391
{
8492
$this->assertTrue($this->propertyAccessor->isWritable($collection, $path));
8593
}
94+
95+
/**
96+
* @dataProvider getInvalidPropertyPaths
97+
*/
98+
public function testIsNotWritable($collection, $path)
99+
{
100+
$this->assertFalse($this->propertyAccessor->isWritable($collection, $path));
101+
}
86102
}

0 commit comments

Comments
 (0)