File tree Expand file tree Collapse file tree 4 files changed +40
-3
lines changed
src/Symfony/Component/PropertyAccess Expand file tree Collapse file tree 4 files changed +40
-3
lines changed Original file line number Diff line number Diff line change 11CHANGELOG
22=========
33
4+ 2.5.0
5+ ------
6+
7+ * allowed non alpha numeric characters in second level and deeper object properties names
8+
492.3.0
510------
611
Original file line number Diff line number Diff 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 ) {
Original file line number Diff line number Diff 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 */
Original file line number Diff line number Diff 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 /**
You can’t perform that action at this time.
0 commit comments