Sfoglia il codice sorgente

[Form] PropertyPath now can handle elements with special characters

Bernhard Schussek 14 anni fa
parent
commit
e787d5dc22

+ 1 - 1
src/Symfony/Component/Form/Util/PropertyPath.php

@@ -64,7 +64,7 @@ class PropertyPath implements \IteratorAggregate
         $remaining = $propertyPath;
 
         // first element is evaluated differently - no leading dot for properties
-        $pattern = '/^((\w+)|\[([^\]]+)\])(.*)/';
+        $pattern = '/^(([^\.\[]+)|\[([^\]]+)\])(.*)/';
 
         while (preg_match($pattern, $remaining, $matches)) {
             if ($matches[2] !== '') {

+ 9 - 0
tests/Symfony/Tests/Component/Form/PropertyPathTest.php

@@ -48,6 +48,15 @@ class PropertyPathTest extends \PHPUnit_Framework_TestCase
         $this->assertEquals('Bernhard', $path->getValue($array));
     }
 
+    public function testGetValueReadsElementWithSpecialCharsExceptDOt()
+    {
+        $array = array('#!@$' => 'Bernhard');
+
+        $path = new PropertyPath('#!@$');
+
+        $this->assertEquals('Bernhard', $path->getValue($array));
+    }
+
     public function testGetValueReadsNestedIndexWithSpecialChars()
     {
         $array = array('root' => array('#!@$.' => 'Bernhard'));