Browse Source

ZF-11363: Allow dashes in keys of yaml files

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24786 44c647ce-9c0f-0410-b52a-842ac1e357ba
adamlundrigan 13 years ago
parent
commit
b7846c432c

+ 1 - 1
library/Zend/Config/Yaml.php

@@ -310,7 +310,7 @@ class Zend_Config_Yaml extends Zend_Config
                 $inIndent      = true;
             }
 
-            if (preg_match("/(\w+):\s*(.*)/", $line, $m)) {
+            if (preg_match("/(?!-)([\w\-]+):\s*(.*)/", $line, $m)) {
                 // key: value
                 if (strlen($m[2])) {
                     // simple key: value

+ 11 - 1
tests/Zend/Config/YamlTest.php

@@ -415,5 +415,15 @@ class Zend_Config_YamlTest extends PHPUnit_Framework_TestCase
         $config = new Zend_Config_Yaml($this->_yamlSingleQuotedString);
         $this->assertEquals('two', $config->one);
     }
-    
+
+    /**
+    * @group ZF-11363
+    */
+    public function testAllowsDashesInLists()
+    {
+        $config = new Zend_Config_Yaml($this->_iniFileSameNameKeysConfig, null);
+        $this->assertEquals('101112', $config->{'te-n'}->{'ele-ven'}->{0}->{'twel-ve'});
+        $this->assertEquals('101112', $config->{'te-n'}->{'ele-ven'}->{0}->twelve);
+        $this->assertEquals('thir-teen', $config->{'te-n'}->{'ele-ven'}->{1});
+    }
 }

+ 8 - 0
tests/Zend/Config/_files/array.yaml

@@ -20,3 +20,11 @@ six:
     - 
       eight: 3
       nine: 3
+te-n: 
+  ele-ven: 
+    - 
+      twel-ve: 101112
+      twelve: 101112
+      
+    - thir-teen
+