bug #14395 [Validator] Property paths starting with 0 are broken. (fago)

This PR was squashed before being merged into the 2.7 branch (closes #14395).

Discussion
----------

[Validator] Property paths starting with 0 are broken.

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #14394
| License       | MIT
| Doc PR        | -

Commits
-------

1ced8da [Validator] Property paths starting with 0 are broken.
This commit is contained in:
Bernhard Schussek 2015-05-04 09:18:53 +02:00
commit f6c77ff362
3 changed files with 6 additions and 5 deletions

View File

@ -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.'),
);
}
}

View File

@ -17,6 +17,7 @@ namespace Symfony\Component\Validator\Util;
* For more extensive functionality, use Symfony's PropertyAccess component.
*
* @since 2.5
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class PropertyPath
@ -42,7 +43,7 @@ class PropertyPath
return $basePath.$subPath;
}
return $basePath ? $basePath.'.'.$subPath : $subPath;
return '' !== (string) $basePath ? $basePath.'.'.$subPath : $subPath;
}
return $basePath;

View File

@ -34,6 +34,7 @@ use Symfony\Component\Validator\Util\PropertyPath;
* Recursive implementation of {@link ContextualValidatorInterface}.
*
* @since 2.5
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
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,