From 0b350d5ddaacd9b471712db122e9473c7ed073d7 Mon Sep 17 00:00:00 2001 From: Huong Nguyen Date: Fri, 3 Feb 2023 14:42:07 +0700 Subject: [PATCH] Fix PHP8.2 str_split function returns empty arrays for empty strings --- src/PhpSpreadsheet/Calculation/Engineering/ConvertHex.php | 2 +- src/PhpSpreadsheet/Calculation/Engineering/ConvertOctal.php | 2 +- src/PhpSpreadsheet/Calculation/MathTrig/Arabic.php | 2 +- src/PhpSpreadsheet/Reader/Csv/Delimiter.php | 2 +- src/PhpSpreadsheet/Reader/Security/XmlScanner.php | 2 +- .../ConditionalFormattingRuleExtension.php | 2 +- src/PhpSpreadsheet/Style/NumberFormat/DateFormatter.php | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) 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..2d49c5f746 100644 --- a/src/PhpSpreadsheet/Reader/Csv/Delimiter.php +++ b/src/PhpSpreadsheet/Reader/Csv/Delimiter.php @@ -60,7 +60,7 @@ protected function countPotentialDelimiters(): void protected function countDelimiterValues(string $line, array $delimiterKeys): void { - $splitString = str_split($line, 1); + $splitString = mb_str_split($line, 1); if (is_array($splitString)) { $distribution = array_count_values($splitString); $countLine = array_intersect_key($distribution, $delimiterKeys); 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])); } }