Browse Source

ZF-11329
Fixed handling of inline comments in values


git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23882 44c647ce-9c0f-0410-b52a-842ac1e357ba

adamlundrigan 14 years ago
parent
commit
d79ff1a1af

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

@@ -315,7 +315,7 @@ class Zend_Config_Yaml extends Zend_Config
                 // key: value
                 if (strlen($m[2])) {
                     // simple key: value
-                    $value = $m[2];
+                    $value = rtrim(preg_replace("/#.*$/", "", $m[2]));
                     // Check for booleans and constants
                     if (preg_match('/^(t(rue)?|on|y(es)?)$/i', $value)) {
                         $value = true;

+ 19 - 0
tests/Zend/Config/YamlTest.php

@@ -46,6 +46,7 @@ class Zend_Config_YamlTest extends PHPUnit_Framework_TestCase
         $this->_badIndentationConfig      = dirname(__FILE__) . '/_files/badindentation.yaml';
         $this->_booleansConfig            = dirname(__FILE__) . '/_files/booleans.yaml';
         $this->_constantsConfig           = dirname(__FILE__) . '/_files/constants.yaml';
+        $this->_yamlInlineCommentsConfig  = dirname(__FILE__) . '/_files/inlinecomments.yaml';
     }
 
     public function testLoadSingleSection()
@@ -315,4 +316,22 @@ class Zend_Config_YamlTest extends PHPUnit_Framework_TestCase
         $this->assertEquals('ZEND_CONFIG_YAML_ENV', $config->env);
         $this->assertEquals('ZEND_CONFIG_YAML_ENV_PATH/test/this', $config->path);
     }
+    
+    /**
+     * @group ZF-11329
+     */
+    public function testAllowsInlineCommentsInValuesUsingHash()
+    {
+        $config = new Zend_Config_Yaml($this->_yamlInlineCommentsConfig, null);
+        $this->assertInstanceOf('Zend_Config', $config->resources);
+        $this->assertInstanceOf('Zend_Config', $config->resources->frontController);
+        $this->assertInternalType(
+            'string', 
+            $config->resources->frontController->controllerDirectory
+        );
+        $this->assertSame(
+            'APPLICATION_PATH/controllers',
+            $config->resources->frontController->controllerDirectory
+        );
+    }
 }

+ 3 - 0
tests/Zend/Config/_files/inlinecomments.yaml

@@ -0,0 +1,3 @@
+resources:
+    frontController:
+        controllerDirectory: APPLICATION_PATH/controllers #heynow!