Skip to content

Commit

Permalink
Fix PHP8.2 str_split function returns empty arrays for empty strings
Browse files Browse the repository at this point in the history
  • Loading branch information
HuongNV13 committed Feb 3, 2023
1 parent e573b45 commit 0b350d5
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/Engineering/ConvertHex.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/MathTrig/Arabic.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Reader/Csv/Delimiter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Reader/Security/XmlScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Style/NumberFormat/DateFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
}
}

0 comments on commit 0b350d5

Please sign in to comment.