From d8a757ce759983320343d84567a9b820b0932ff5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Lorenzo=20Rodr=C3=ADguez?= Date: Wed, 10 Mar 2010 15:16:02 -0430 Subject: [PATCH] Fixing empty value check to avoid a mistaken default value selection in Helper::value. closes #290 --- cake/libs/view/helper.php | 2 +- cake/tests/cases/libs/view/helper.test.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/cake/libs/view/helper.php b/cake/libs/view/helper.php index 43ef30f8f9b..20e1f0335ad 100644 --- a/cake/libs/view/helper.php +++ b/cake/libs/view/helper.php @@ -700,7 +700,7 @@ function value($options = array(), $field = null, $key = 'value') { } if (is_array($options)) { - if (empty($result) && isset($options['default'])) { + if ($result === null && isset($options['default'])) { $result = $options['default']; } unset($options['default']); diff --git a/cake/tests/cases/libs/view/helper.test.php b/cake/tests/cases/libs/view/helper.test.php index d546a68773d..804f325c59c 100644 --- a/cake/tests/cases/libs/view/helper.test.php +++ b/cake/tests/cases/libs/view/helper.test.php @@ -385,6 +385,19 @@ function testValue() { $this->Helper->setEntity('HelperTestTag.HelperTestTag'); $result = $this->Helper->value('HelperTestTag.HelperTestTag'); $this->assertEqual($result, array(3 => 3, 5 => 5)); + + $this->Helper->data = array('zero' => 0); + $this->Helper->setEntity('zero'); + $result = $this->Helper->value(array('default' => 'something'), 'zero'); + $this->assertEqual($result, array('value' => 0)); + + $this->Helper->data = array('zero' => '0'); + $result = $this->Helper->value(array('default' => 'something'), 'zero'); + $this->assertEqual($result, array('value' => '0')); + + $this->Helper->setEntity('inexistent'); + $result = $this->Helper->value(array('default' => 'something'), 'inexistent'); + $this->assertEqual($result, array('value' => 'something')); } /**