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

Skip to content

[Validator] Prevent infinite loop in PropertyMetadata #20146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Symfony/Component/Validator/Mapping/PropertyMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,14 @@ public function getPropertyValue($object)
*/
protected function newReflectionMember($objectOrClassName)
{
$originalClass = is_string($objectOrClassName) ? $objectOrClassName : get_class($objectOrClassName);

while (!property_exists($objectOrClassName, $this->getName())) {
$objectOrClassName = get_parent_class($objectOrClassName);

if (false === $objectOrClassName) {
throw new ValidatorException(sprintf('Property "%s" does not exist in class "%s"', $this->getName(), $originalClass));
}
}

$member = new \ReflectionProperty($objectOrClassName, $this->getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,14 @@ public function testGetPropertyValueFromOverriddenPrivateProperty()
$this->assertTrue($metadata->isPublic($entity));
$this->assertEquals('Overridden data', $metadata->getPropertyValue($entity));
}

public function testGetPropertyValueFromRemovedProperty()
{
$entity = new Entity('foobar');
$metadata = new PropertyMetadata(self::CLASSNAME, 'internal');
$metadata->name = 'test';

$this->setExpectedException('Symfony\Component\Validator\Exception\ValidatorException');
$metadata->getPropertyValue($entity);
}
}