Skip to content

Commit

Permalink
[Validator] Ensure numeric subpaths do not cause errors on PHP 7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpott authored and Tobion committed Oct 25, 2019
1 parent 5d097d2 commit 6244a1e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function provideAppendPaths()
['foo', 'bar', 'foo.bar', 'It append the subPath to the basePath'],
['foo', '[bar]', 'foo[bar]', 'It does not include the dot separator if subPath uses the array notation'],
['0', 'bar', '0.bar', 'Leading zeros are kept.'],
['0', 1, '0.1', 'Numeric subpaths do not cause PHP 7.4 errors.'],
];
}
}
5 changes: 3 additions & 2 deletions src/Symfony/Component/Validator/Util/PropertyPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ class PropertyPath
*/
public static function append($basePath, $subPath)
{
if ('' !== (string) $subPath) {
$subPath = (string) $subPath;
if ('' !== $subPath) {
if ('[' === $subPath[0]) {
return $basePath.$subPath;
}

return '' !== (string) $basePath ? $basePath.'.'.$subPath : $subPath;
return '' !== $basePath ? $basePath.'.'.$subPath : $subPath;
}

return $basePath;
Expand Down

0 comments on commit 6244a1e

Please sign in to comment.