From c4acfad109b650991e517b1c51c237a2b6b54810 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sat, 29 Oct 2022 15:26:58 +1100 Subject: [PATCH] [REF][PHP8.2] Remove usage of utf8_decode in favour of mb_strlen --- CRM/Utils/Rule.php | 2 +- api/v3/utils.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CRM/Utils/Rule.php b/CRM/Utils/Rule.php index 1a1a6e9a67..a396045737 100644 --- a/CRM/Utils/Rule.php +++ b/CRM/Utils/Rule.php @@ -222,7 +222,7 @@ class CRM_Utils_Rule { $url = 'http://' . $_SERVER['HTTP_HOST'] . $url; } // Convert URLs with Unicode to ASCII - if (strlen($url) != strlen(utf8_decode($url))) { + if (strlen($url) != mb_strlen($url)) { $url = self::idnToAsci($url); } return (bool) filter_var($url, FILTER_VALIDATE_URL); diff --git a/api/v3/utils.php b/api/v3/utils.php index 504d7d0fec..648defa7e1 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -2288,8 +2288,8 @@ function _civicrm_api3_validate_string(&$params, &$fieldName, &$fieldInfo, $enti } } // Check our field length - elseif (is_string($fieldValue) && !empty($fieldInfo['maxlength']) && strlen(utf8_decode($fieldValue)) > $fieldInfo['maxlength']) { - throw new CRM_Core_Exception("Value for $fieldName is " . strlen(utf8_decode($value)) . " characters - This field has a maxlength of {$fieldInfo['maxlength']} characters.", + elseif (is_string($fieldValue) && !empty($fieldInfo['maxlength']) && mb_strlen($fieldValue ?? '') > $fieldInfo['maxlength']) { + throw new CRM_Core_Exception("Value for $fieldName is " . mb_strlen($value ?? '') . " characters - This field has a maxlength of {$fieldInfo['maxlength']} characters.", 2100, ['field' => $fieldName] ); } -- 2.25.1