diff --git a/src/PhpSpreadsheet/Calculation/Engineering/ConvertHex.php b/src/PhpSpreadsheet/Calculation/Engineering/ConvertHex.php index 55ce209ecd..c0e9e458ea 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/ConvertHex.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/ConvertHex.php @@ -96,7 +96,7 @@ public static function toDecimal($value) } $binX = ''; - foreach (str_split($value) as $char) { + foreach (mb_str_split($value) as $char) { $binX .= str_pad(base_convert($char, 16, 2), 4, '0', STR_PAD_LEFT); } if (strlen($binX) == 40 && $binX[0] == '1') { diff --git a/src/PhpSpreadsheet/Calculation/Engineering/ConvertOctal.php b/src/PhpSpreadsheet/Calculation/Engineering/ConvertOctal.php index add7aba01b..44af5cff4e 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/ConvertOctal.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/ConvertOctal.php @@ -96,7 +96,7 @@ public static function toDecimal($value) } $binX = ''; - foreach (str_split($value) as $char) { + foreach (mb_str_split($value) as $char) { $binX .= str_pad(decbin((int) $char), 3, '0', STR_PAD_LEFT); } if (strlen($binX) == 30 && $binX[0] == '1') { diff --git a/src/PhpSpreadsheet/Calculation/MathTrig/Arabic.php b/src/PhpSpreadsheet/Calculation/MathTrig/Arabic.php index ee4885057f..bdc0e500e9 100644 --- a/src/PhpSpreadsheet/Calculation/MathTrig/Arabic.php +++ b/src/PhpSpreadsheet/Calculation/MathTrig/Arabic.php @@ -60,7 +60,7 @@ private static function mollifyScrutinizer($value): array private static function strSplit(string $roman): array { - $rslt = str_split($roman); + $rslt = mb_str_split($roman); return self::mollifyScrutinizer($rslt); } diff --git a/src/PhpSpreadsheet/Reader/Csv/Delimiter.php b/src/PhpSpreadsheet/Reader/Csv/Delimiter.php index 029d4a186e..02360b4262 100644 --- a/src/PhpSpreadsheet/Reader/Csv/Delimiter.php +++ b/src/PhpSpreadsheet/Reader/Csv/Delimiter.php @@ -60,14 +60,12 @@ protected function countPotentialDelimiters(): void protected function countDelimiterValues(string $line, array $delimiterKeys): void { - $splitString = str_split($line, 1); - if (is_array($splitString)) { - $distribution = array_count_values($splitString); - $countLine = array_intersect_key($distribution, $delimiterKeys); + $splitString = mb_str_split($line, 1); + $distribution = array_count_values($splitString); + $countLine = array_intersect_key($distribution, $delimiterKeys); - foreach (self::POTENTIAL_DELIMETERS as $delimiter) { - $this->counts[$delimiter][] = $countLine[$delimiter] ?? 0; - } + foreach (self::POTENTIAL_DELIMETERS as $delimiter) { + $this->counts[$delimiter][] = $countLine[$delimiter] ?? 0; } } diff --git a/src/PhpSpreadsheet/Reader/Security/XmlScanner.php b/src/PhpSpreadsheet/Reader/Security/XmlScanner.php index ad898ae410..56040d190a 100644 --- a/src/PhpSpreadsheet/Reader/Security/XmlScanner.php +++ b/src/PhpSpreadsheet/Reader/Security/XmlScanner.php @@ -145,7 +145,7 @@ public function scan($xml) $xml = $this->toUtf8($xml); // Don't rely purely on libxml_disable_entity_loader() - $pattern = '/\\0?' . implode('\\0?', /** @scrutinizer ignore-type */ str_split($this->pattern)) . '\\0?/'; + $pattern = '/\\0?' . implode('\\0?', /** @scrutinizer ignore-type */ mb_str_split($this->pattern)) . '\\0?/'; if (preg_match($pattern, $xml)) { throw new Reader\Exception('Detected use of ENTITY in XML, spreadsheet file load() aborted to prevent XXE/XEE attacks'); diff --git a/src/PhpSpreadsheet/Style/ConditionalFormatting/ConditionalFormattingRuleExtension.php b/src/PhpSpreadsheet/Style/ConditionalFormatting/ConditionalFormattingRuleExtension.php index 0cdbc36851..9cfdc94262 100644 --- a/src/PhpSpreadsheet/Style/ConditionalFormatting/ConditionalFormattingRuleExtension.php +++ b/src/PhpSpreadsheet/Style/ConditionalFormatting/ConditionalFormattingRuleExtension.php @@ -40,7 +40,7 @@ public function __construct(?string $id = null, string $cfRule = self::CONDITION private function generateUuid(): string { - $chars = str_split('xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'); + $chars = mb_str_split('xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'); foreach ($chars as $i => $char) { if ($char === 'x') { diff --git a/src/PhpSpreadsheet/Style/NumberFormat/DateFormatter.php b/src/PhpSpreadsheet/Style/NumberFormat/DateFormatter.php index ba54b53593..2901327266 100644 --- a/src/PhpSpreadsheet/Style/NumberFormat/DateFormatter.php +++ b/src/PhpSpreadsheet/Style/NumberFormat/DateFormatter.php @@ -177,6 +177,6 @@ private static function setLowercaseCallback(array $matches): string private static function escapeQuotesCallback(array $matches): string { - return '\\' . implode('\\', /** @scrutinizer ignore-type */ str_split($matches[1])); + return '\\' . implode('\\', /** @scrutinizer ignore-type */ mb_str_split($matches[1])); } } diff --git a/tests/data/Calculation/Engineering/HEX2DEC.php b/tests/data/Calculation/Engineering/HEX2DEC.php index 0ecdd30c1e..aaf5c2e000 100644 --- a/tests/data/Calculation/Engineering/HEX2DEC.php +++ b/tests/data/Calculation/Engineering/HEX2DEC.php @@ -24,4 +24,5 @@ [-2147483648, '"ff80000000"'], [2147483648, '"80000000"'], [2147483647, '"7fffffff"'], + [0, '""'], ]; diff --git a/tests/data/Calculation/Engineering/OCT2DEC.php b/tests/data/Calculation/Engineering/OCT2DEC.php index 8ee3a170db..b234b58a48 100644 --- a/tests/data/Calculation/Engineering/OCT2DEC.php +++ b/tests/data/Calculation/Engineering/OCT2DEC.php @@ -17,4 +17,5 @@ ['#NUM!', '"37777777770"'], // too many digits [536870911, '"3777777777"'], // highest positive [-536870912, '"4000000000"'], // lowest negative + ['0', '""'], ]; diff --git a/tests/data/Calculation/MathTrig/ARABIC.php b/tests/data/Calculation/MathTrig/ARABIC.php index e2a6f46bfd..2d1ae004b4 100644 --- a/tests/data/Calculation/MathTrig/ARABIC.php +++ b/tests/data/Calculation/MathTrig/ARABIC.php @@ -57,4 +57,8 @@ '#VALUE!', 'WRONG', ], + [ + 0, + '', + ], ];