Index: library/Zend/Config/Yaml.php =================================================================== --- library/Zend/Config/Yaml.php (revision 24628) +++ library/Zend/Config/Yaml.php (working copy) @@ -126,7 +126,7 @@ * * @param string $yaml YAML file to process * @param mixed $section Section to process - * @param array|boolean $options + * @param array|boolean $options */ public function __construct($yaml, $section = null, $options = false) { @@ -285,7 +285,7 @@ $inIndent = false; while (list($n, $line) = each($lines)) { $lineno = $n + 1; - + $line = rtrim(preg_replace("/#.*$/", "", $line)); if (strlen($line) == 0) { continue; @@ -314,16 +314,8 @@ // key: value if (strlen($m[2])) { // simple key: value - $value = rtrim(preg_replace("/#.*$/", "", $m[2])); - // Check for booleans and constants - if (preg_match('/^(t(rue)?|on|y(es)?)$/i', $value)) { - $value = true; - } elseif (preg_match('/^(f(alse)?|off|n(o)?)$/i', $value)) { - $value = false; - } elseif (!self::$_ignoreConstants) { - // test for constants - $value = self::_replaceConstants($value); - } + $value = preg_replace("/#.*$/", "", $m[2]); + $value = self::_parseValue($value); } else { // key: and then values on new lines $value = self::_decodeYaml($currentIndent + 1, $lines); @@ -337,14 +329,8 @@ // - FOO if (strlen($line) > 2) { $value = substr($line, 2); - if (preg_match('/^(t(rue)?|on|y(es)?)$/i', $value)) { - $value = true; - } elseif (preg_match('/^(f(alse)?|off|n(o)?)$/i', $value)) { - $value = false; - } elseif (!self::$_ignoreConstants) { - $value = self::_replaceConstants($value); - } - $config[] = $value; + + $config[] = self::_parseValue($value); } else { $config[] = self::_decodeYaml($currentIndent + 1, $lines); } @@ -360,6 +346,38 @@ } /** + * Parse values + * + * @param string $value + * @return string + */ + protected static function _parseValue($value) + { + $value = trim($value); + + // remove quotes from string. + if ('"' == $value['0']) { + if ('"' == $value[count($value) -1]) { + $value = substr($value, 1, -1); + } + } elseif ('\'' == $value['0'] && '\'' == $value[count($value) -1]) { + $value = strtr($value, array("''" => "'", "'" => '')); + } + + // Check for booleans and constants + if (preg_match('/^(t(rue)?|on|y(es)?)$/i', $value)) { + $value = true; + } elseif (preg_match('/^(f(alse)?|off|n(o)?)$/i', $value)) { + $value = false; + } elseif (!self::$_ignoreConstants) { + // test for constants + $value = self::_replaceConstants($value); + } + + return $value; + } + + /** * Replace any constants referenced in a string with their values * * @param string $value Index: tests/Zend/Config/YamlTest.php =================================================================== --- tests/Zend/Config/YamlTest.php (revision 24628) +++ tests/Zend/Config/YamlTest.php (working copy) @@ -50,6 +50,7 @@ $this->_yamlIndentedCommentsConfig = dirname(__FILE__) . '/_files/indentedcomments.yaml'; $this->_yamlListConstantsConfig = dirname(__FILE__) . '/_files/listconstants.yaml'; $this->_listBooleansConfig = dirname(__FILE__) . '/_files/listbooleans.yaml'; + $this->_yamlSingleQuotedString = dirname(__FILE__) . '/_files/zf11934.yaml'; } public function testLoadSingleSection() @@ -406,4 +407,13 @@ $this->assertFalse($config->usingCapitalOff->{0}); } + /** + * @group ZF-11934 + */ + public function testAllowsSingleQuotedStringValues() + { + $config = new Zend_Config_Yaml($this->_yamlSingleQuotedString); + $this->assertEquals('two', $config->one); + } + } Index: tests/Zend/Config/_files/zf11934.yaml =================================================================== --- tests/Zend/Config/_files/zf11934.yaml (revision 0) +++ tests/Zend/Config/_files/zf11934.yaml (revision 0) @@ -0,0 +1 @@ +one: 'two' \ No newline at end of file