Skip to content

Commit 88a954c

Browse files
committed
bug #11117 [Validator] Fix array notation in the PropertyPath::append() (jakzal)
This PR was submitted for the master branch but it was merged into the 2.5 branch instead (closes #11117). Discussion ---------- [Validator] Fix array notation in the PropertyPath::append() | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | related #11072 #11046 (not fixed yet) | License | MIT | Doc PR | - Commits ------- aa6b08d [Validator] Fix array notation in the PropertyPath::append()
2 parents 057c274 + aa6b08d commit 88a954c

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Validator\Tests\Util;
13+
14+
use Symfony\Component\Validator\Util\PropertyPath;
15+
16+
class PropertyPathTest extends \PHPUnit_Framework_TestCase
17+
{
18+
/**
19+
* @dataProvider provideAppendPaths
20+
*/
21+
public function testAppend($basePath, $subPath, $expectedPath, $message)
22+
{
23+
$this->assertSame($expectedPath, PropertyPath::append($basePath, $subPath), $message);
24+
}
25+
26+
public function provideAppendPaths()
27+
{
28+
return array(
29+
array('foo', '', 'foo', 'It returns the basePath if subPath is empty'),
30+
array('', 'bar', 'bar', 'It returns the subPath if basePath is empty'),
31+
array('foo', 'bar', 'foo.bar', 'It append the subPath to the basePath'),
32+
array('foo', '[bar]', 'foo[bar]', 'It does not include the dot separator if subPath uses the array notation')
33+
);
34+
}
35+
}

src/Symfony/Component/Validator/Util/PropertyPath.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class PropertyPath
3838
public static function append($basePath, $subPath)
3939
{
4040
if ('' !== (string) $subPath) {
41-
if ('[' === $subPath{1}) {
41+
if ('[' === $subPath{0}) {
4242
return $basePath.$subPath;
4343
}
4444

0 commit comments

Comments
 (0)