From 44023b658e446796efff3685e5a37ca9f0135ae0 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Fri, 13 Dec 2019 06:43:02 +1100 Subject: [PATCH] dev/core#1469 Mitigate for users that are running ICU 4.4 as the constant is only defined in ICU 4.6 --- HTML/QuickForm/Rule/Email.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/HTML/QuickForm/Rule/Email.php b/HTML/QuickForm/Rule/Email.php index 0b5be47d7..4abed48d4 100644 --- a/HTML/QuickForm/Rule/Email.php +++ b/HTML/QuickForm/Rule/Email.php @@ -37,6 +37,25 @@ */ class HTML_QuickForm_Rule_Email extends HTML_QuickForm_Rule { + + /** + * Compatibility layer for PHP versions running ICU 4.4, as the constant INTL_IDNA_VARIANT_UTS46 + * is only available as of ICU 4.6. + * + * Please note: Once PHP 7.4 is the minimum requirement, this method will vanish without further notice + * as it is recommended to use the native method instead, when working against a clean environment. + * + * @param string $part. + * @return string|bool + */ + private static function idn_to_ascii($part) + { + if (defined('INTL_IDNA_VARIANT_UTS46')) { + return idn_to_ascii($part, 0, INTL_IDNA_VARIANT_UTS46); + } + return idn_to_ascii($part); + } + // switching to a better regex as per CRM-40 // var $regex = '/^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$/'; var $regex = '/^([a-zA-Z0-9&_?\/`!|#*$^%=~{}+\'-]+|"([\x00-\x0C\x0E-\x21\x23-\x5B\x5D-\x7F]|\\[\x00-\x7F])*")(\.([a-zA-Z0-9&_?\/`!|#*$^%=~{}+\'-]+|"([\x00-\x0C\x0E-\x21\x23-\x5B\x5D-\x7F]|\\[\x00-\x7F])*"))*@([a-zA-Z0-9&_?\/`!|#*$^%=~{}+\'-]+|\[([\x00-\x0C\x0E-\x5A\x5E-\x7F]|\\[\x00-\x7F])*\])(\.([a-zA-Z0-9&_?\/`!|#*$^%=~{}+\'-]+|\[([\x00-\x0C\x0E-\x5A\x5E-\x7F]|\\[\x00-\x7F])*\]))*$/'; @@ -55,7 +74,7 @@ function validate($email, $checkDomain = false) if ($parts = explode('@', $email)) { if (sizeof($parts) == 2) { foreach ($parts as &$part) { - $part = idn_to_ascii($part, 0, INTL_IDNA_VARIANT_UTS46); + $part = self::idn_to_ascii($part); } $email = implode('@', $parts); }