From eac32294ed9ce2c8274a780d3661ba6724405148 Mon Sep 17 00:00:00 2001 From: Andrea Ruggiero Date: Fri, 20 Dec 2019 10:03:53 +0100 Subject: [PATCH 1/2] Skip conversion if charset is the same --- src/MbWrapper.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/MbWrapper.php b/src/MbWrapper.php index 3c7cea6..111f9e5 100644 --- a/src/MbWrapper.php +++ b/src/MbWrapper.php @@ -334,6 +334,11 @@ private function getNormalizedCharset($charset) */ public function convert($str, $fromCharset, $toCharset) { + // Skip conversion if charset is the same + if ($fromCharset === $toCharset) { + return $str; + } + // there may be some mb-supported encodings not supported by iconv (on my libiconv for instance // HZ isn't supported), and so it may happen that failing an mb_convert_encoding, an iconv // may also fail even though both support an encoding separately. From 87e6f4b51b35b5fa5608e64f8004bbcd491b5f03 Mon Sep 17 00:00:00 2001 From: Andrea Ruggiero Date: Sat, 28 Dec 2019 23:14:30 +0100 Subject: [PATCH 2/2] Check for same charset after normalizing it --- src/MbWrapper.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/MbWrapper.php b/src/MbWrapper.php index 111f9e5..aff9cb5 100644 --- a/src/MbWrapper.php +++ b/src/MbWrapper.php @@ -334,11 +334,7 @@ private function getNormalizedCharset($charset) */ public function convert($str, $fromCharset, $toCharset) { - // Skip conversion if charset is the same - if ($fromCharset === $toCharset) { - return $str; - } - + // there may be some mb-supported encodings not supported by iconv (on my libiconv for instance // HZ isn't supported), and so it may happen that failing an mb_convert_encoding, an iconv // may also fail even though both support an encoding separately. @@ -346,6 +342,11 @@ public function convert($str, $fromCharset, $toCharset) $from = $this->getMbCharset($fromCharset); $to = $this->getMbCharset($toCharset); + + // Skip conversion if charset is the same + if ($from === $to) { + return $str; + } if ($str !== '') { if ($from !== false && $to === false) {