From 5ba3bfc895f1350346533fd6f0c0087a59dea7ee Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 16 Jan 2014 09:56:28 -0800 Subject: [PATCH] CRM-14028 - Workaround the number 0 == empty() php bug --- CRM/Core/BAO/Tag.php | 4 +++- api/v3/Generic/Setvalue.php | 4 +++- api/v3/utils.php | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CRM/Core/BAO/Tag.php b/CRM/Core/BAO/Tag.php index 3689539a98..2ba2c9a1dd 100644 --- a/CRM/Core/BAO/Tag.php +++ b/CRM/Core/BAO/Tag.php @@ -356,7 +356,9 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag { * @static */ static function dataExists(&$params) { - if (!empty($params['name'])) { + // Disallow empty values except for the number zero. + // TODO: create a utility for this since it's needed in many places + if (!empty($params['name']) || (string) $params['name'] === '0') { return TRUE; } diff --git a/api/v3/Generic/Setvalue.php b/api/v3/Generic/Setvalue.php index 471e700aca..9802d97bc5 100644 --- a/api/v3/Generic/Setvalue.php +++ b/api/v3/Generic/Setvalue.php @@ -26,7 +26,9 @@ function civicrm_api3_generic_setValue($apiRequest) { } $def = $fields[$field]; - if (array_key_exists('required', $def) && empty($value)) { + // Disallow empty values except for the number zero. + // TODO: create a utility for this since it's needed in many places + if (array_key_exists('required', $def) && empty($value) && $value !== '0' && $value !== 0) { return civicrm_api3_create_error(ts("This can't be empty, please provide a value"), array("error_code" => "required", "field" => $field)); } diff --git a/api/v3/utils.php b/api/v3/utils.php index 59ba512613..f810fcbf42 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -116,7 +116,9 @@ function civicrm_api3_verify_mandatory($params, $daoName = NULL, $keys = array( } } else { - if (!array_key_exists($key, $params) || empty($params[$key])) { + // Disallow empty values except for the number zero. + // TODO: create a utility for this since it's needed in many places + if (!array_key_exists($key, $params) || (empty($params[$key]) && $params[$key] !== 0 && $params[$key] !== '0')) { $unmatched[] = $key; } } -- 2.25.1