X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FUtils%2FRule.php;h=4e63ec01035caf9f9868335d9452508b35b7bb72;hb=e790ecfe2928d5a2f3128116a2b75e3dd49dc871;hp=9c5707925cb1648c056ed64661dda82cfaa9b258;hpb=1a813170fa7f3b06df46a6753bb0852e72bf39a0;p=civicrm-core.git diff --git a/CRM/Utils/Rule.php b/CRM/Utils/Rule.php index 9c5707925c..4e63ec0103 100644 --- a/CRM/Utils/Rule.php +++ b/CRM/Utils/Rule.php @@ -261,10 +261,10 @@ class CRM_Utils_Rule { } /** - * @param $value + * @param string $value * @param null $default * - * @return null + * @return string|null */ public static function date($value, $default = NULL) { if (is_string($value) && @@ -276,10 +276,10 @@ class CRM_Utils_Rule { } /** - * @param $value + * @param string $value * @param null $default * - * @return null|string + * @return string|null */ public static function dateTime($value, $default = NULL) { $result = $default; @@ -639,12 +639,46 @@ class CRM_Utils_Rule { * * @return bool */ - public static function email($value) { + public static function email($value): bool { + if (function_exists('idn_to_ascii')) { + $parts = explode('@', $value); + foreach ($parts as &$part) { + // if the function returns FALSE then let filter_var have at it. + $part = self::idnToAsci($part) ?: $part; + if ($part === 'localhost') { + // if we are in a dev environment add .com to trick it into accepting localhost. + // this is a bit best-effort - ie we don't really care that it's in a bigger if. + $part .= '.com'; + } + } + $value = implode('@', $parts); + } return (bool) filter_var($value, FILTER_VALIDATE_EMAIL); } /** - * @param $list + * Convert domain string to ascii. + * + * See https://lab.civicrm.org/dev/core/-/issues/2769 + * and also discussion over in guzzle land + * https://github.com/guzzle/guzzle/pull/2454 + * + * @param string $string + * + * @return string|false + */ + private static function idnToAsci(string $string) { + if (!\extension_loaded('intl')) { + return $string; + } + if (defined('INTL_IDNA_VARIANT_UTS46')) { + return idn_to_ascii($string, 0, INTL_IDNA_VARIANT_UTS46); + } + return idn_to_ascii($string); + } + + /** + * @param string $list * * @return bool */ @@ -721,24 +755,6 @@ class CRM_Utils_Rule { return $success; } - /** - * See how file rules are written in HTML/QuickForm/file.php - * Checks to make sure the uploaded file is html - * - * @param array $elementValue - * - * @return bool - * True if file has been uploaded, false otherwise - */ - public static function htmlFile($elementValue) { - if ((isset($elementValue['error']) && $elementValue['error'] == 0) || - (!empty($elementValue['tmp_name']) && $elementValue['tmp_name'] != 'none') - ) { - return CRM_Utils_File::isHtmlFile($elementValue['tmp_name']); - } - return FALSE; - } - /** * Check if there is a record with the same name in the db. *