Преглед на файлове

[Form] PropertyPath now can handle elements with special characters

Bernhard Schussek преди 14 години
родител
ревизия
e787d5dc22
променени са 2 файла, в които са добавени 10 реда и са изтрити 1 реда
  1. 1 1
      src/Symfony/Component/Form/Util/PropertyPath.php
  2. 9 0
      tests/Symfony/Tests/Component/Form/PropertyPathTest.php

+ 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'));