From b3db07f5f28af158513d2a0f09f4290a6beb4201 Mon Sep 17 00:00:00 2001 From: fago Date: Sat, 18 Apr 2015 11:56:47 +0200 Subject: [PATCH] [Validator] Property paths starting with 0 are broken. --- .../Component/Validator/Tests/Util/PropertyPathTest.php | 1 + src/Symfony/Component/Validator/Util/PropertyPath.php | 3 ++- .../Validator/Validator/RecursiveContextualValidator.php | 7 +++---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Component/Validator/Tests/Util/PropertyPathTest.php b/src/Symfony/Component/Validator/Tests/Util/PropertyPathTest.php index 94802b66ec..a8b9af9de8 100644 --- a/src/Symfony/Component/Validator/Tests/Util/PropertyPathTest.php +++ b/src/Symfony/Component/Validator/Tests/Util/PropertyPathTest.php @@ -30,6 +30,7 @@ class PropertyPathTest extends \PHPUnit_Framework_TestCase array('', 'bar', 'bar', 'It returns the subPath if basePath is empty'), array('foo', 'bar', 'foo.bar', 'It append the subPath to the basePath'), array('foo', '[bar]', 'foo[bar]', 'It does not include the dot separator if subPath uses the array notation'), + array('0', 'bar', '0.bar', 'Leading zeros are kept.'), ); } } diff --git a/src/Symfony/Component/Validator/Util/PropertyPath.php b/src/Symfony/Component/Validator/Util/PropertyPath.php index 4d397a9124..3ef8a8b1dc 100644 --- a/src/Symfony/Component/Validator/Util/PropertyPath.php +++ b/src/Symfony/Component/Validator/Util/PropertyPath.php @@ -17,6 +17,7 @@ namespace Symfony\Component\Validator\Util; * For more extensive functionality, use Symfony's PropertyAccess component. * * @since 2.5 + * * @author Bernhard Schussek */ class PropertyPath @@ -42,7 +43,7 @@ class PropertyPath return $basePath.$subPath; } - return $basePath ? $basePath.'.'.$subPath : $subPath; + return '' !== (string) $basePath ? $basePath.'.'.$subPath : $subPath; } return $basePath; diff --git a/src/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php b/src/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php index 191decdce4..d632d05d3f 100644 --- a/src/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php +++ b/src/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php @@ -34,6 +34,7 @@ use Symfony\Component\Validator\Util\PropertyPath; * Recursive implementation of {@link ContextualValidatorInterface}. * * @since 2.5 + * * @author Bernhard Schussek */ class RecursiveContextualValidator implements ContextualValidatorInterface @@ -526,7 +527,7 @@ class RecursiveContextualValidator implements ContextualValidatorInterface } elseif ($metadata->isGroupSequenceProvider()) { // The group sequence is dynamically obtained from the validated // object - /** @var \Symfony\Component\Validator\GroupSequenceProviderInterface $object */ + /* @var \Symfony\Component\Validator\GroupSequenceProviderInterface $object */ $group = $object->getGroupSequence(); $defaultOverridden = true; @@ -590,9 +591,7 @@ class RecursiveContextualValidator implements ContextualValidatorInterface $object, $cacheKey.':'.$propertyName, $propertyMetadata, - $propertyPath - ? $propertyPath.'.'.$propertyName - : $propertyName, + PropertyPath::append($propertyPath, $propertyName), $groups, $cascadedGroups, TraversalStrategy::IMPLICIT,