feature #9843 [PropertyAccess] Allowed non alphanumeric chars in object properties (florianv)
This PR was merged into the 2.5-dev branch.
Discussion
----------
[PropertyAccess] Allowed non alphanumeric chars in object properties
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | https://github.com/symfony/symfony/issues/8930
| License | MIT
| Doc PR |
Commits
-------
20d4eb6
[PropertyAccess] Allowed non alphanumeric chars in object properties
This commit is contained in:
commit
2b7af1245e
@ -1,6 +1,11 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
2.5.0
|
||||
------
|
||||
|
||||
* allowed non alpha numeric characters in second level and deeper object properties names
|
||||
|
||||
2.3.0
|
||||
------
|
||||
|
||||
|
@ -118,7 +118,7 @@ class PropertyPath implements \IteratorAggregate, PropertyPathInterface
|
||||
|
||||
$position += strlen($matches[1]);
|
||||
$remaining = $matches[4];
|
||||
$pattern = '/^(\.(\w+)|\[([^\]]+)\])(.*)/';
|
||||
$pattern = '/^(\.([^\.|\[]+)|\[([^\]]+)\])(.*)/';
|
||||
}
|
||||
|
||||
if ('' !== $remaining) {
|
||||
|
@ -137,6 +137,13 @@ class PropertyAccessorTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('Bernhard', $this->getPropertyAccessor()->getValue($array, '%!@$§'));
|
||||
}
|
||||
|
||||
public function testGetValueReadsPropertyWithSpecialCharsExceptDotNested()
|
||||
{
|
||||
$object = (object) array('nested' => (object) array('@child' => 'foo'));
|
||||
|
||||
$this->assertEquals('foo', $this->getPropertyAccessor()->getValue($object, 'nested.@child'));
|
||||
}
|
||||
|
||||
public function testGetValueReadsPropertyWithCustomPropertyPath()
|
||||
{
|
||||
$object = new Author();
|
||||
@ -328,6 +335,17 @@ class PropertyAccessorTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('Schussek', $object->getLastName());
|
||||
}
|
||||
|
||||
public function testSetValueWithSpecialCharsNested()
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$person = new \stdClass();
|
||||
$person->{'@email'} = null;
|
||||
$object->person = $person;
|
||||
|
||||
$this->getPropertyAccessor()->setValue($object, 'person.@email', 'bar');
|
||||
$this->assertEquals('bar', $object->person->{'@email'});
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException
|
||||
*/
|
||||
|
@ -38,12 +38,26 @@ class PropertyPathTest extends \PHPUnit_Framework_TestCase
|
||||
new PropertyPath('.property');
|
||||
}
|
||||
|
||||
public function providePathsContainingUnexpectedCharacters()
|
||||
{
|
||||
return array(
|
||||
array('property.'),
|
||||
array('property.['),
|
||||
array('property..'),
|
||||
array('property['),
|
||||
array('property[['),
|
||||
array('property[.'),
|
||||
array('property[]'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providePathsContainingUnexpectedCharacters
|
||||
* @expectedException \Symfony\Component\PropertyAccess\Exception\InvalidPropertyPathException
|
||||
*/
|
||||
public function testUnexpectedCharacters()
|
||||
public function testUnexpectedCharacters($path)
|
||||
{
|
||||
new PropertyPath('property.$foo');
|
||||
new PropertyPath($path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user