Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2b7af12

Browse filesBrowse files
committed
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 | #8930 | License | MIT | Doc PR | Commits ------- 20d4eb6 [PropertyAccess] Allowed non alphanumeric chars in object properties
2 parents c0e4c4a + 20d4eb6 commit 2b7af12
Copy full SHA for 2b7af12

File tree

Expand file treeCollapse file tree

4 files changed

+40
-3
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+40
-3
lines changed

‎src/Symfony/Component/PropertyAccess/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyAccess/CHANGELOG.md
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
2.5.0
5+
------
6+
7+
* allowed non alpha numeric characters in second level and deeper object properties names
8+
49
2.3.0
510
------
611

‎src/Symfony/Component/PropertyAccess/PropertyPath.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyAccess/PropertyPath.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function __construct($propertyPath)
118118

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

124124
if ('' !== $remaining) {

‎src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,13 @@ public function testGetValueReadsPropertyWithSpecialCharsExceptDot()
137137
$this->assertEquals('Bernhard', $this->getPropertyAccessor()->getValue($array, '%!@$§'));
138138
}
139139

140+
public function testGetValueReadsPropertyWithSpecialCharsExceptDotNested()
141+
{
142+
$object = (object) array('nested' => (object) array('@child' => 'foo'));
143+
144+
$this->assertEquals('foo', $this->getPropertyAccessor()->getValue($object, 'nested.@child'));
145+
}
146+
140147
public function testGetValueReadsPropertyWithCustomPropertyPath()
141148
{
142149
$object = new Author();
@@ -328,6 +335,17 @@ public function testSetValueCamelizesSetterNames()
328335
$this->assertEquals('Schussek', $object->getLastName());
329336
}
330337

338+
public function testSetValueWithSpecialCharsNested()
339+
{
340+
$object = new \stdClass();
341+
$person = new \stdClass();
342+
$person->{'@email'} = null;
343+
$object->person = $person;
344+
345+
$this->getPropertyAccessor()->setValue($object, 'person.@email', 'bar');
346+
$this->assertEquals('bar', $object->person->{'@email'});
347+
}
348+
331349
/**
332350
* @expectedException \Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException
333351
*/

‎src/Symfony/Component/PropertyAccess/Tests/PropertyPathTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyAccess/Tests/PropertyPathTest.php
+16-2Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,26 @@ public function testDotCannotBePresentAtTheBeginning()
3838
new PropertyPath('.property');
3939
}
4040

41+
public function providePathsContainingUnexpectedCharacters()
42+
{
43+
return array(
44+
array('property.'),
45+
array('property.['),
46+
array('property..'),
47+
array('property['),
48+
array('property[['),
49+
array('property[.'),
50+
array('property[]'),
51+
);
52+
}
53+
4154
/**
55+
* @dataProvider providePathsContainingUnexpectedCharacters
4256
* @expectedException \Symfony\Component\PropertyAccess\Exception\InvalidPropertyPathException
4357
*/
44-
public function testUnexpectedCharacters()
58+
public function testUnexpectedCharacters($path)
4559
{
46-
new PropertyPath('property.$foo');
60+
new PropertyPath($path);
4761
}
4862

4963
/**

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.