Skip to content

Commit 2332c19

Browse files
jakzalfabpot
authored andcommitted
[Validator] Fix array notation in the PropertyPath::append()
1 parent 20fd949 commit 2332c19

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

Tests/Util/PropertyPathTest.php

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 <[email protected]>
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+
}

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)