Replaced StrToLowerIfAscii() for the better mb_strtolower()

This commit is contained in:
djmaze 2021-11-23 12:23:28 +01:00
parent 6a4bd6044a
commit b0463f3bff
7 changed files with 17 additions and 28 deletions

View file

@ -206,30 +206,16 @@ abstract class Utils
public static function IsAscii(string $sValue) : bool public static function IsAscii(string $sValue) : bool
{ {
if ('' === \trim($sValue)) return '' === \trim($sValue)
{ || !\preg_match('/[^\x09\x10\x13\x0A\x0D\x20-\x7E]/', $sValue);
return true;
}
return !\preg_match('/[^\x09\x10\x13\x0A\x0D\x20-\x7E]/', $sValue);
} }
public static function StrToLowerIfAscii(string $sValue) : string public static function StrMailDomainToLower(string $sValue) : string
{
return static::IsAscii($sValue) ? \strtolower($sValue) : $sValue;
}
public static function StrToUpperIfAscii(string $sValue) : string
{
return static::IsAscii($sValue) ? \strtoupper($sValue) : $sValue;
}
public static function StrMailDomainToLowerIfAscii(string $sValue) : string
{ {
$aParts = \explode('@', $sValue, 2); $aParts = \explode('@', $sValue, 2);
if (!empty($aParts[1])) if (!empty($aParts[1]))
{ {
$aParts[1] = static::IsAscii($aParts[1]) ? \strtolower($aParts[1]) : $aParts[1]; $aParts[1] = \mb_strtolower($aParts[1]);
} }
return \implode('@', $aParts); return \implode('@', $aParts);
@ -1385,12 +1371,12 @@ abstract class Utils
catch (\Throwable $oException) {} catch (\Throwable $oException) {}
} }
return $bLowerIfAscii ? static::StrMailDomainToLowerIfAscii($sStr) : $sStr; return $bLowerIfAscii ? static::StrMailDomainToLower($sStr) : $sStr;
} }
public static function IdnToAscii(string $sStr, bool $bLowerIfAscii = false) : string public static function IdnToAscii(string $sStr, bool $bLowerIfAscii = false) : string
{ {
$sStr = $bLowerIfAscii ? static::StrMailDomainToLowerIfAscii($sStr) : $sStr; $sStr = $bLowerIfAscii ? static::StrMailDomainToLower($sStr) : $sStr;
$sUser = ''; $sUser = '';
$sDomain = $sStr; $sDomain = $sStr;

View file

@ -29,7 +29,7 @@ trait UserAuth
$sEmail = \MailSo\Base\Utils::Trim($sEmail); $sEmail = \MailSo\Base\Utils::Trim($sEmail);
if ($this->Config()->Get('login', 'login_lowercase', true)) { if ($this->Config()->Get('login', 'login_lowercase', true)) {
$sEmail = \MailSo\Base\Utils::StrToLowerIfAscii($sEmail); $sEmail = \mb_strtolower($sEmail);
} }
if (false === \strpos($sEmail, '@')) { if (false === \strpos($sEmail, '@')) {
@ -104,7 +104,7 @@ trait UserAuth
$sLogin = $sEmail; $sLogin = $sEmail;
if ($this->Config()->Get('login', 'login_lowercase', true)) { if ($this->Config()->Get('login', 'login_lowercase', true)) {
$sLogin = \MailSo\Base\Utils::StrToLowerIfAscii($sLogin); $sLogin = \mb_strtolower($sLogin);
} }
$this->Plugins()->RunHook('login.credentials', array(&$sEmail, &$sLogin, &$sPassword)); $this->Plugins()->RunHook('login.credentials', array(&$sEmail, &$sLogin, &$sPassword));

View file

@ -409,7 +409,7 @@ trait CardDAV
if (\preg_match('/\|(.+)$/', $sUrl, $aMatch) && !empty($aMatch[1])) if (\preg_match('/\|(.+)$/', $sUrl, $aMatch) && !empty($aMatch[1]))
{ {
$sUserAddressBookNameName = \trim($aMatch[1]); $sUserAddressBookNameName = \trim($aMatch[1]);
$sUserAddressBookNameName = \MailSo\Base\Utils::StrToLowerIfAscii($sUserAddressBookNameName); $sUserAddressBookNameName = \mb_strtolower($sUserAddressBookNameName);
$sUrl = \preg_replace('/\|(.+)$/', '', $sUrl); $sUrl = \preg_replace('/\|(.+)$/', '', $sUrl);
} }
@ -434,7 +434,7 @@ trait CardDAV
{ {
foreach ($aPaths as $sKey => $sValue) foreach ($aPaths as $sKey => $sValue)
{ {
$sValue = \MailSo\Base\Utils::StrToLowerIfAscii(\trim($sValue)); $sValue = \mb_strtolower(\trim($sValue));
if ($sValue === $sUserAddressBookNameName) if ($sValue === $sUserAddressBookNameName)
{ {
$sNewPath = $sKey; $sNewPath = $sKey;
@ -447,7 +447,7 @@ trait CardDAV
{ {
foreach ($aPaths as $sKey => $sValue) foreach ($aPaths as $sKey => $sValue)
{ {
$sValue = \MailSo\Base\Utils::StrToLowerIfAscii($sValue); $sValue = \mb_strtolower($sValue);
if (\in_array($sValue, array('contacts', 'default', 'addressbook', 'address book'))) if (\in_array($sValue, array('contacts', 'default', 'addressbook', 'address book')))
{ {
$sNewPath = $sKey; $sNewPath = $sKey;

View file

@ -120,7 +120,7 @@ class Property implements \JsonSerializable
// lower // lower
if ($this->IsEmail()) if ($this->IsEmail())
{ {
$this->Value = \MailSo\Base\Utils::StrMailDomainToLowerIfAscii($this->Value); $this->Value = \MailSo\Base\Utils::StrMailDomainToLower($this->Value);
} }
if ($this->IsName()) if ($this->IsName())

View file

@ -1020,7 +1020,7 @@ class PdoAddressBook
{ {
if ($aItem && !empty($aItem['prop_value'])) if ($aItem && !empty($aItem['prop_value']))
{ {
$aExists[] = \MailSo\Base\Utils::StrToLowerIfAscii(\trim($aItem['prop_value'])); $aExists[] = \mb_strtolower(\trim($aItem['prop_value']));
} }
} }
} }

View file

@ -91,7 +91,7 @@ class Service
$bAdmin = !empty($aPaths[0]) && \strtolower($aPaths[0]) === $sAdminPanelKey; $bAdmin = !empty($aPaths[0]) && \strtolower($aPaths[0]) === $sAdminPanelKey;
} }
else if (empty($aPaths[0]) && else if (empty($aPaths[0]) &&
\MailSo\Base\Utils::StrToLowerIfAscii($sAdminPanelHost) === \MailSo\Base\Utils::StrToLowerIfAscii($this->oHttp->GetHost())) \mb_strtolower($sAdminPanelHost) === \mb_strtolower($this->oHttp->GetHost()))
{ {
$bAdmin = true; $bAdmin = true;
} }

View file

@ -146,6 +146,9 @@ if (defined('APP_VERSION'))
define('APP_PLUGINS_PATH', APP_PRIVATE_DATA.'plugins/'); define('APP_PLUGINS_PATH', APP_PRIVATE_DATA.'plugins/');
mb_internal_encoding('UTF-8');
mb_language('uni');
if (APP_VERSION !== $sInstalled || (!is_dir(APP_PRIVATE_DATA) && strlen($sPrivateDataFolderInternalName) && '_default_' !== APP_PRIVATE_DATA_NAME)) if (APP_VERSION !== $sInstalled || (!is_dir(APP_PRIVATE_DATA) && strlen($sPrivateDataFolderInternalName) && '_default_' !== APP_PRIVATE_DATA_NAME))
{ {
define('APP_INSTALLED_START', true); define('APP_INSTALLED_START', true);