From 2803d961298b4b9b1a5c9a33743cc48cf211c738 Mon Sep 17 00:00:00 2001 From: oleibman <10341515+oleibman@users.noreply.github.com> Date: Mon, 1 Sep 2025 07:45:27 -0700 Subject: [PATCH] Cover Important Path in StringHelper --- src/PhpSpreadsheet/Shared/StringHelper.php | 2 +- .../Shared/StringHelperNoIconv.php | 18 ++++++++++++++++++ .../Shared/StringHelperTest.php | 10 ++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 tests/PhpSpreadsheetTests/Shared/StringHelperNoIconv.php 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)); + } }