diff --git a/src/PhpSpreadsheet/Shared/StringHelper.php b/src/PhpSpreadsheet/Shared/StringHelper.php index a354bf8e3..51ec36339 100644 --- a/src/PhpSpreadsheet/Shared/StringHelper.php +++ b/src/PhpSpreadsheet/Shared/StringHelper.php @@ -426,7 +426,7 @@ class StringHelper */ public static function convertEncoding(string $textValue, string $to, string $from): string { - if (self::getIsIconvEnabled()) { + if (static::getIsIconvEnabled()) { $result = iconv($from, $to . self::$iconvOptions, $textValue); if (false !== $result) { return $result; diff --git a/tests/PhpSpreadsheetTests/Shared/StringHelperNoIconv.php b/tests/PhpSpreadsheetTests/Shared/StringHelperNoIconv.php new file mode 100644 index 000000000..9f0644aca --- /dev/null +++ b/tests/PhpSpreadsheetTests/Shared/StringHelperNoIconv.php @@ -0,0 +1,18 @@ +expectExceptionMessage('Unable to convert to string'); StringHelper::convertToString($dt); } + + public function testNoIconv(): void + { + $string = "\xBF"; // inverted question mark in ISO-8859-1 + $expected = '¿'; + $from = 'ISO-8859-1'; + $to = 'UTF-8'; + self::assertSame($expected, StringHelper::convertEncoding($string, $to, $from)); + self::assertSame($expected, StringHelperNoIconv::convertEncoding($string, $to, $from)); + } }