From 43b6f1595a9beeb2261216780632ff1600ac0de8 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sun, 27 Sep 2015 11:24:25 -0400 Subject: [PATCH] Fixes for CRM_Utils_Type --- CRM/Utils/Type.php | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/CRM/Utils/Type.php b/CRM/Utils/Type.php index 35baff8e20..be390ae230 100644 --- a/CRM/Utils/Type.php +++ b/CRM/Utils/Type.php @@ -165,37 +165,33 @@ class CRM_Utils_Type { break; case 'Positive': - // CRM-8925 the 3 below are for custom fields of this type + if (CRM_Utils_Rule::positiveInteger($data)) { + return (int) $data; + } + break; + + // CRM-8925 for custom fields of this type case 'Country': case 'StateProvince': - // Checked for multi valued state/country value if (is_array($data)) { - $returnData = TRUE; - // @todo Reuse of the $data variable = asking for trouble. - // @todo This code will always return the last item in the array. Intended? - foreach ($data as $data) { - if (CRM_Utils_Rule::positiveInteger($data) || CRM_Core_DAO::escapeString($data)) { - $returnData = TRUE; - } - else { - $returnData = FALSE; + $valid = TRUE; + foreach ($data as $item) { + if (!CRM_Utils_Rule::positiveInteger($item)) { + $valid = FALSE; } } - if ($returnData) { + if ($valid) { return $data; } } - elseif (!is_numeric($data) && CRM_Core_DAO::escapeString($data)) { - return $data; - } elseif (CRM_Utils_Rule::positiveInteger($data)) { - return $data; + return (int) $data; } break; case 'File': if (CRM_Utils_Rule::positiveInteger($data)) { - return $data; + return (int) $data; } break; -- 2.25.1