Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PHP8.2 str_split function returns empty arrays for empty strings #588

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions include/barcodes/qrcode.php
Original file line number Diff line number Diff line change
@@ -638,7 +638,8 @@ public function __construct($code, $eclevel = 'L') {
$barcode_array['bcode'] = array();
foreach ($qrTab as $line) {
$arrAdd = array();
foreach (str_split($line) as $char) {
$chars = function_exists('mb_str_split') ? mb_str_split($line) : str_split($line);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like incorrect indentation, project uses tabs while this code introduces spaces. Same can be said about all other new lines in this MR.

foreach ($chars as $char) {
$arrAdd[] = ($char=='1')?1:0;
}
$barcode_array['bcode'][] = $arrAdd;
@@ -1307,7 +1308,8 @@ protected function eatNum() {
return $this->eatAn();
}
}
$this->items = $this->appendNewInputItem($this->items, QR_MODE_NM, $run, str_split($this->dataStr));
$data = function_exists('mb_str_split') ? mb_str_split($this->dataStr) : str_split($this->dataStr);
$this->items = $this->appendNewInputItem($this->items, QR_MODE_NM, $run, $data);
return $run;
}

@@ -1346,7 +1348,8 @@ protected function eatAn() {
return $this->eat8();
}
}
$this->items = $this->appendNewInputItem($this->items, QR_MODE_AN, $run, str_split($this->dataStr));
$data = function_exists('mb_str_split') ? mb_str_split($this->dataStr) : str_split($this->dataStr);
$this->items = $this->appendNewInputItem($this->items, QR_MODE_AN, $run, $data);
return $run;
}

@@ -1359,7 +1362,8 @@ protected function eatKanji() {
while($this->identifyMode($p) == QR_MODE_KJ) {
$p += 2;
}
$this->items = $this->appendNewInputItem($this->items, QR_MODE_KJ, $p, str_split($this->dataStr));
$data = function_exists('mb_str_split') ? mb_str_split($this->dataStr) : str_split($this->dataStr);
$this->items = $this->appendNewInputItem($this->items, QR_MODE_KJ, $p, $data);
$run = $p;
return $run;
}
@@ -1409,7 +1413,8 @@ protected function eat8() {
}
}
$run = $p;
$this->items = $this->appendNewInputItem($this->items, QR_MODE_8B, $run, str_split($this->dataStr));
$data = function_exists('mb_str_split') ? mb_str_split($this->dataStr) : str_split($this->dataStr);
$this->items = $this->appendNewInputItem($this->items, QR_MODE_8B, $run, $data);
return $run;
}

2 changes: 1 addition & 1 deletion include/tcpdf_fonts.php
Original file line number Diff line number Diff line change
@@ -2004,7 +2004,7 @@ public static function UTF8StringToArray($str, $isunicode, &$currentfont) {
$chars = TCPDF_STATIC::pregSplit('//','u', $str, -1, PREG_SPLIT_NO_EMPTY);
$carr = array_map(array('TCPDF_FONTS', 'uniord'), $chars);
} else {
$chars = str_split($str);
$chars = function_exists('mb_str_split') ? mb_str_split($str) : str_split($str);
$carr = array_map('ord', $chars);
}
if (is_array($currentfont['subsetchars']) && is_array($carr)) {
4 changes: 2 additions & 2 deletions tcpdf_barcodes_1d.php
Original file line number Diff line number Diff line change
@@ -2179,8 +2179,8 @@ protected function barcode_imb_pre($code) {
if (!preg_match('/^[fadtFADT]{65}$/', $code) == 1) {
return false;
}
$characters = str_split(strtolower($code), 1);
// build bars
$characters = function_exists('mb_str_split') ? mb_str_split(strtolower($code), 1) : str_split(strtolower($code), 1);
// build bars
$k = 0;
$bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 3, 'bcode' => array());
for ($i = 0; $i < 65; ++$i) {
4 changes: 2 additions & 2 deletions tcpdf_barcodes_2d.php
Original file line number Diff line number Diff line change
@@ -320,8 +320,8 @@ public function setBarcode($code, $type) {
$this->barcode_array['num_cols'] = strlen($rows[0]);
$this->barcode_array['bcode'] = array();
foreach ($rows as $r) {
$this->barcode_array['bcode'][] = str_split($r, 1);
}
$this->barcode_array['bcode'][] = function_exists('mb_str_split') ? mb_str_split($r, 1) : str_split($r, 1);
}
$this->barcode_array['code'] = $code;
break;
}