[REF][PHP8.2] Remove usage of utf8_decode in favour of mb_strlen
authorSeamus Lee <seamuslee001@gmail.com>
Sat, 29 Oct 2022 04:26:58 +0000 (15:26 +1100)
committerSeamus Lee <seamuslee001@gmail.com>
Sat, 29 Oct 2022 04:26:58 +0000 (15:26 +1100)
CRM/Utils/Rule.php
api/v3/utils.php

index 1a1a6e9a67f0967b8c388e600c9cef0684705786..a396045737226ac0d1c77bfd032b416376d7f10b 100644 (file)
@@ -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);
index 504d7d0fec55bab83c3d6a3d5075452f0096c0a4..648defa7e1f25de4e0b8fd0b83df084efca47e9f 100644 (file)
@@ -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]
     );
   }