From 79e7e16e187a107e79dd67a531207d2eb9420444 Mon Sep 17 00:00:00 2001 From: cay89 Date: Thu, 5 Jan 2023 13:43:03 +0100 Subject: [PATCH] [Console] Fix computing column width containing multibyte chars --- Helper/Table.php | 2 +- Tests/Helper/TableTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Helper/Table.php b/Helper/Table.php index 3f2d99145..5c3447ab3 100644 --- a/Helper/Table.php +++ b/Helper/Table.php @@ -805,7 +805,7 @@ private function calculateColumnsWidth(iterable $groups) $textContent = Helper::removeDecoration($this->output->getFormatter(), $cell); $textLength = Helper::width($textContent); if ($textLength > 0) { - $contentColumns = str_split($textContent, ceil($textLength / $cell->getColspan())); + $contentColumns = mb_str_split($textContent, ceil($textLength / $cell->getColspan())); foreach ($contentColumns as $position => $content) { $row[$i + $position] = $content; } diff --git a/Tests/Helper/TableTest.php b/Tests/Helper/TableTest.php index 2d70bd271..53001d428 100644 --- a/Tests/Helper/TableTest.php +++ b/Tests/Helper/TableTest.php @@ -316,7 +316,7 @@ public function renderProvider() ], new TableSeparator(), [ - new TableCell('Cupiditate dicta atque porro, tempora exercitationem modi animi nulla nemo vel nihil!', ['colspan' => 3]), + new TableCell('Cupìdĭtâte díctá âtquè pôrrò, tèmpórà exercitátìónèm mòdí ânìmí núllà nèmò vèl níhìl!', ['colspan' => 3]), ], ], 'default', @@ -333,7 +333,7 @@ public function renderProvider() | 9971-5-0210-0 | A Tale of | | | Two Cities | +-------------------------------+-------------------------------+-----------------------------+ -| Cupiditate dicta atque porro, tempora exercitationem modi animi nulla nemo vel nihil! | +| Cupìdĭtâte díctá âtquè pôrrò, tèmpórà exercitátìónèm mòdí ânìmí núllà nèmò vèl níhìl! | +-------------------------------+-------------------------------+-----------------------------+ TABLE