Update idn convertion methods (#6115)

* Add more test cases
* Update phpdoc
pull/6116/head
Daniel Kesselberg 7 years ago committed by Aleksander Machniak
parent 869882f8db
commit a8d5547163

@ -596,8 +596,7 @@ class rcube_utils
// %s - domain name after the '@' from e-mail address provided at login screen.
// Returns FALSE if an invalid email is provided
if (strpos($name, '%s') !== false) {
$user_email = self::get_input_value('_user', self::INPUT_POST);
$user_email = self::idn_convert($user_email, true);
$user_email = self::idn_to_ascii(self::get_input_value('_user', self::INPUT_POST));
$matches = preg_match('/(.*)@([a-z0-9\.\-\[\]\:]+)/i', $user_email, $s);
if ($matches < 1 || filter_var($s[1]."@".$s[2], FILTER_VALIDATE_EMAIL) === false) {
return false;
@ -871,24 +870,36 @@ class rcube_utils
return $date;
}
/*
* Idn_to_ascii wrapper.
* Intl/Idn modules version of this function doesn't work with e-mail address
/**
* Wrapper for idn_to_ascii with support for e-mail address
*
* @param string $str Decoded e-mail address
* @return string Encoded e-mail address
*/
public static function idn_to_ascii($str)
{
return self::idn_convert($str, true);
}
/*
* Idn_to_ascii wrapper.
* Intl/Idn modules version of this function doesn't work with e-mail address
/**
* Wrapper for idn_to_utf8 with support for e-mail address
*
* @param string $str Decoded e-mail address
* @return string Encoded e-mail address
*/
public static function idn_to_utf8($str)
{
return self::idn_convert($str, false);
}
/**
* Convert a string to ascii or utf8
*
* @param string $input Decoded e-mail address
* @param boolean $is_utf Convert by idn_to_ascii if true and idn_to_utf8 if false
* @return string Encoded e-mail address
*/
public static function idn_convert($input, $is_utf = false)
{
if ($at = strpos($input, '@')) {
@ -896,6 +907,7 @@ class rcube_utils
$domain = substr($input, $at + 1);
}
else {
$user = '';
$domain = $input;
}

@ -570,6 +570,15 @@ class Framework_Utils extends PHPUnit_Framework_TestCase
array('test@рф.ru', 'test@xn--p1ai.ru'),
array('test@δοκιμή.gr', 'test@xn--jxalpdlp.gr'),
array('test@gwóźdź.pl', 'test@xn--gwd-hna98db.pl'),
array('рф.ru@рф.ru', 'рф.ru@xn--p1ai.ru'),
array('vermögensberater', 'xn--vermgensberater-ctb'),
array('vermögensberatung', 'xn--vermgensberatung-pwb'),
array('グーグル', 'xn--qcka1pmc'),
array('谷歌', 'xn--flw351e'),
array('中信', 'xn--fiq64b'),
array('рф.ru', 'xn--p1ai.ru'),
array('δοκιμή.gr', 'xn--jxalpdlp.gr'),
array('gwóźdź.pl', 'xn--gwd-hna98db.pl'),
);
}

Loading…
Cancel
Save