Skip to content

[PropertyAccess] Allowed non alphanumeric chars in object properties #9843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 23, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Symfony/Component/PropertyAccess/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

2.5.0
------

* allowed non alpha numeric characters in second level and deeper object properties names

2.3.0
------

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/PropertyAccess/PropertyPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function __construct($propertyPath)

$position += strlen($matches[1]);
$remaining = $matches[4];
$pattern = '/^(\.(\w+)|\[([^\]]+)\])(.*)/';
$pattern = '/^(\.([^\.|\[]+)|\[([^\]]+)\])(.*)/';
}

if ('' !== $remaining) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ public function testGetValueReadsPropertyWithSpecialCharsExceptDot()
$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();
Expand Down Expand Up @@ -328,6 +335,17 @@ public function testSetValueCamelizesSetterNames()
$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
*/
Expand Down
18 changes: 16 additions & 2 deletions src/Symfony/Component/PropertyAccess/Tests/PropertyPathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,26 @@ public function testDotCannotBePresentAtTheBeginning()
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);
}

/**
Expand Down