Issues

ZF-12277: Zend_Config_Yaml does not support null value

Description

http://www.yaml.org/spec/1.2/spec.html#id2803362 Probably this patch fixes:


diff --git a/Config/Yaml.php b/Config/Yaml.php
index 5f5ba84..c0b1c36 100755
--- a/Config/Yaml.php
+++ b/Config/Yaml.php
@@ -320,6 +320,8 @@ class Zend_Config_Yaml extends Zend_Config
                         $value = true;
                     } elseif (preg_match('/^(f(alse)?|off|n(o)?)$/i', $value)) {
                         $value = false;
+                    } elseif (preg_match('/^null$/i', $value)) {
+                        $value = null;
                     } elseif (!self::$_ignoreConstants) {
                         // test for constants
                         $value = self::_replaceConstants($value);

Comments

This needs a unit test before it can be added to the framework.


diff --git library/Zend/Config/Yaml.php library/Zend/Config/Yaml.php
index 5f5ba84..c0b1c36 100755
--- library/Zend/Config/Yaml.php
+++ library/Zend/Config/Yaml.php
@@ -320,6 +320,8 @@ class Zend_Config_Yaml extends Zend_Config
                         $value = true;
                     } elseif (preg_match('/^(f(alse)?|off|n(o)?)$/i', $value)) {
                         $value = false;
+                    } elseif (preg_match('/^null$/i', $value)) {
+                        $value = null;
                     } elseif (!self::$_ignoreConstants) {
                         // test for constants
                         $value = self::_replaceConstants($value);
diff --git tests/Zend/Config/YamlTest.php tests/Zend/Config/YamlTest.php
index 92140be..79c0b9b 100755
--- tests/Zend/Config/YamlTest.php
+++ tests/Zend/Config/YamlTest.php
@@ -290,6 +290,17 @@ class Zend_Config_YamlTest extends PHPUnit_Framework_TestCase
         $this->assertFalse($config->usingCapitalOff);
     }
 
+    /**
+     * @group ZF-12277
+     */
+    public function testParsesTypesAccordingToOneDotTwoSpecification()
+    {
+        $config = new Zend_Config_Yaml($this->_booleansConfig, 'production');
+        $this->assertNull($config->usingLowerCasedNull);
+        $this->assertNull($config->usingTitleCasedNull);
+        $this->assertNull($config->usingCapitalNull);
+    }
+
     public function testHonorsPhpConstants()
     {
         if (!defined('ZEND_CONFIG_YAML_ENV')) {
diff --git tests/Zend/Config/_files/booleans.yaml tests/Zend/Config/_files/booleans.yaml
index 67a9277..45ee653 100644
--- tests/Zend/Config/_files/booleans.yaml
+++ tests/Zend/Config/_files/booleans.yaml
@@ -27,3 +27,7 @@ production:
     usingTitleCasedOff: Off
     usingCapitalOff: OFF
 
+    usingLowerCasedNull: null
+    usingTitleCasedNull: Null
+    usingCapitalNull: NULL
+

$ php -dinclude_path=.:library/:/usr/lib/php/pear/ /usr/bin/phpunit tests/Zend/Config/YamlTest.php
PHPUnit 3.6.10 by Sebastian Bergmann.

.........................

Time: 0 seconds, Memory: 3.75Mb

OK (25 tests, 100 assertions)

It surely does not make any sense to use regular expressions for a simple comparision:


+                    } elseif (preg_match('/^null$/i', $value)) {

How about:


+                    } elseif (strcasecmp($value, 'null') === 0) {

fixed in trunk (25168) and release-1.12 (25169)