Skip to content

Commit

Permalink
feature #9843 [PropertyAccess] Allowed non alphanumeric chars in obje…
Browse files Browse the repository at this point in the history
…ct 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 | #8930
| License       | MIT
| Doc PR        |

Commits
-------

20d4eb6 [PropertyAccess] Allowed non alphanumeric chars in object properties
  • Loading branch information
fabpot committed Dec 23, 2013
2 parents c0e4c4a + 20d4eb6 commit 2b7af12
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
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

0 comments on commit 2b7af12

Please sign in to comment.