diff --git a/src/Symfony/Component/PropertyAccess/CHANGELOG.md b/src/Symfony/Component/PropertyAccess/CHANGELOG.md index 071ef3b520..fb5ebfa550 100644 --- a/src/Symfony/Component/PropertyAccess/CHANGELOG.md +++ b/src/Symfony/Component/PropertyAccess/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +2.5.0 +------ + + * allowed non alpha numeric characters in second level and deeper object properties names + 2.3.0 ------ diff --git a/src/Symfony/Component/PropertyAccess/PropertyPath.php b/src/Symfony/Component/PropertyAccess/PropertyPath.php index 840fc71572..833dd0543b 100644 --- a/src/Symfony/Component/PropertyAccess/PropertyPath.php +++ b/src/Symfony/Component/PropertyAccess/PropertyPath.php @@ -118,7 +118,7 @@ class PropertyPath implements \IteratorAggregate, PropertyPathInterface $position += strlen($matches[1]); $remaining = $matches[4]; - $pattern = '/^(\.(\w+)|\[([^\]]+)\])(.*)/'; + $pattern = '/^(\.([^\.|\[]+)|\[([^\]]+)\])(.*)/'; } if ('' !== $remaining) { diff --git a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php index a64930a93a..72fbfe428f 100644 --- a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php +++ b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php @@ -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 */ diff --git a/src/Symfony/Component/PropertyAccess/Tests/PropertyPathTest.php b/src/Symfony/Component/PropertyAccess/Tests/PropertyPathTest.php index 4e77a913ff..c6f1fd6e14 100644 --- a/src/Symfony/Component/PropertyAccess/Tests/PropertyPathTest.php +++ b/src/Symfony/Component/PropertyAccess/Tests/PropertyPathTest.php @@ -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); } /**