From b702598b0bb0d03b994b567156bb584003f23388 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Fri, 7 Jun 2019 11:25:07 -0400 Subject: [PATCH] Fixing bug where PropertyInfoLoader tried to add validation to non-existent properties --- .../Component/Validator/Mapping/Loader/PropertyInfoLoader.php | 4 ++++ .../Validator/Tests/Fixtures/PropertyInfoLoaderEntity.php | 4 ++++ .../Validator/Tests/Mapping/Loader/PropertyInfoLoaderTest.php | 1 + 3 files changed, 9 insertions(+) diff --git a/src/Symfony/Component/Validator/Mapping/Loader/PropertyInfoLoader.php b/src/Symfony/Component/Validator/Mapping/Loader/PropertyInfoLoader.php index df3878d6e2..7ddd534275 100644 --- a/src/Symfony/Component/Validator/Mapping/Loader/PropertyInfoLoader.php +++ b/src/Symfony/Component/Validator/Mapping/Loader/PropertyInfoLoader.php @@ -60,6 +60,10 @@ final class PropertyInfoLoader implements LoaderInterface continue; } + if (!property_exists($className, $property)) { + continue; + } + $types = $this->typeExtractor->getTypes($className, $property); if (null === $types) { continue; diff --git a/src/Symfony/Component/Validator/Tests/Fixtures/PropertyInfoLoaderEntity.php b/src/Symfony/Component/Validator/Tests/Fixtures/PropertyInfoLoaderEntity.php index 42f048c5d8..5f2a37179d 100644 --- a/src/Symfony/Component/Validator/Tests/Fixtures/PropertyInfoLoaderEntity.php +++ b/src/Symfony/Component/Validator/Tests/Fixtures/PropertyInfoLoaderEntity.php @@ -48,4 +48,8 @@ class PropertyInfoLoaderEntity public $alreadyPartiallyMappedCollection; public $readOnly; + + public function setNonExistentField() + { + } } diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Loader/PropertyInfoLoaderTest.php b/src/Symfony/Component/Validator/Tests/Mapping/Loader/PropertyInfoLoaderTest.php index 71b2691ee5..f87b19f795 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/Loader/PropertyInfoLoaderTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/Loader/PropertyInfoLoaderTest.php @@ -46,6 +46,7 @@ class PropertyInfoLoaderTest extends TestCase 'alreadyMappedNotBlank', 'alreadyPartiallyMappedCollection', 'readOnly', + 'nonExistentField', ]) ; $propertyInfoStub