[Validator] Fixed PropertyPath to read array indices with special characters
This commit is contained in:
parent
55a97ec78e
commit
50955a3919
@ -63,7 +63,7 @@ class PropertyPath implements \IteratorAggregate
|
||||
$remaining = $propertyPath;
|
||||
|
||||
// first element is evaluated differently - no leading dot for properties
|
||||
$pattern = '/^((\w+)|\[(\w+)\])(.*)/';
|
||||
$pattern = '/^((\w+)|\[([^\]]+)\])(.*)/';
|
||||
|
||||
while (preg_match($pattern, $remaining, $matches)) {
|
||||
if ($matches[2] !== '') {
|
||||
@ -76,7 +76,7 @@ class PropertyPath implements \IteratorAggregate
|
||||
|
||||
$position += strlen($matches[1]);
|
||||
$remaining = $matches[4];
|
||||
$pattern = '/^(\.(\w+)|\[(\w+)\])(.*)/';
|
||||
$pattern = '/^(\.(\w+)|\[([^\]]+)\])(.*)/';
|
||||
}
|
||||
|
||||
if (!empty($remaining)) {
|
||||
|
@ -39,6 +39,24 @@ class PropertyPathTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('Bernhard', $path->getValue($array));
|
||||
}
|
||||
|
||||
public function testGetValueReadsIndexWithSpecialChars()
|
||||
{
|
||||
$array = array('#!@$.' => 'Bernhard');
|
||||
|
||||
$path = new PropertyPath('[#!@$.]');
|
||||
|
||||
$this->assertEquals('Bernhard', $path->getValue($array));
|
||||
}
|
||||
|
||||
public function testGetValueReadsNestedIndexWithSpecialChars()
|
||||
{
|
||||
$array = array('root' => array('#!@$.' => 'Bernhard'));
|
||||
|
||||
$path = new PropertyPath('root[#!@$.]');
|
||||
|
||||
$this->assertEquals('Bernhard', $path->getValue($array));
|
||||
}
|
||||
|
||||
public function testGetValueReadsArrayWithCustomPropertyPath()
|
||||
{
|
||||
$array = array('child' => array('index' => array('firstName' => 'Bernhard')));
|
||||
|
Reference in New Issue
Block a user