From 06fe9657e213d80f1951e9dcd887a112d988c2af Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Fri, 10 Apr 2020 10:04:42 +0900 Subject: [PATCH] Stub fo convert encoding string is actual source encoding check --- www/lib/CoreLibs/Basic.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/www/lib/CoreLibs/Basic.php b/www/lib/CoreLibs/Basic.php index 418084f8..479e05dd 100644 --- a/www/lib/CoreLibs/Basic.php +++ b/www/lib/CoreLibs/Basic.php @@ -2565,17 +2565,33 @@ class Basic } /** - * detects the source encoding of the string and if doesn't match to the given target encoding it convert is + * detects the source encoding of the string and if doesn't match + * to the given target encoding it convert is + * if source encoding is set and auto check is true (default) a second + * check is done so that the source string encoding actually matches + * will be skipped if source encoding detection is ascii * @param string $string string to convert * @param string $to_encoding target encoding * @param string $source_encoding optional source encoding, will try to auto detect + * @param bool $auto_check default true, if source encoding is set + * check that the source is actually matching + * to what we sav the source is * @return string encoding converted string */ - public static function convertEncoding(string $string, string $to_encoding, string $source_encoding = ''): string + public static function convertEncoding(string $string, string $to_encoding, string $source_encoding = '', bool $auto_check = true): string { // set if not given if (!$source_encoding) { $source_encoding = mb_detect_encoding($string); + } else { + $_source_encoding = mb_detect_encoding($string); + } + if ($auto_check === true && + isset($_source_encoding) && + $_source_encoding == $source_encoding + ) { + // trigger check if we have override source encoding. + // if different (_source is all but not ascii) then trigger skip if matching } if ($source_encoding != $to_encoding) { if ($source_encoding) {