Issues

ZF-12277: Zend_Config_Yaml does not support null value

Issue Type: Bug Created: 2012-06-11T23:05:40.000+0000 Last Updated: 2012-12-22T12:23:25.000+0000 Status: Resolved Fix version(s): - 1.12.2 (25/Feb/13)

Reporter: Evgeniy Makhrov (ezh) Assignee: Rob Allen (rob) Tags: - Zend_Config

Related issues: Attachments:

Description

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

<pre class="highlight">
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

Posted by Rob Allen (rob) on 2012-06-13T19:12:13.000+0000

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

Posted by Evgeniy Makhrov (ezh) on 2012-06-13T21:35:03.000+0000

<pre class="highlight">
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
+



<pre class="highlight">
$ 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)

Posted by Ben Scholzen (dasprid) on 2012-06-13T22:46:31.000+0000

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

<pre class="highlight">
+                    } elseif (preg_match('/^null$/i', $value)) {

How about:

<pre class="highlight">
+                    } elseif (strcasecmp($value, 'null') === 0) {

Posted by Rob Allen (rob) on 2012-12-22T12:23:25.000+0000

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

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts