8000 bug #48886 [Console] Fix computing column width containing multibyte … · symfony/symfony@2e66dcc · GitHub
[go: up one dir, main page]

Skip to content

Commit 2e66dcc

Browse files
bug #48886 [Console] Fix computing column width containing multibyte chars (cay89)
This PR was merged into the 5.4 branch. Discussion ---------- [Console] Fix computing column width containing multibyte chars Use mb_str_split instead of str_split because it works badly with multibyte chars on auto width adjustment. | Q | A | ------------- | --- | Branch? | 5.4 and above | Bug fix? | yes Console output with str_split: ![image](https://user-images.githubusercontent.com/3186515/210783727-7f67c371-67c0-4005-9914-e345fa9b5569.png) Console output with mb_str_split: ![image](https://user-images.githubusercontent.com/3186515/210783808-bcd9e754-4831-43a1-86b3-6cbcdd93a3ec.png) Commits ------- f32179e [Console] Fix computing column width containing multibyte chars
2 parents 6366ed2 + f32179e commit 2e66dcc

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/Symfony/Component/Console/Helper/Table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ private function calculateColumnsWidth(iterable $groups)
805805
$textContent = Helper::removeDecoration($this->output->getFormatter(), $cell);
806806
$textLength = Helper::width($textContent);
807807
if ($textLength > 0) {
808-
$contentColumns = str_split($textContent, ceil($textLength / $cell->getColspan()));
808+
$contentColumns = mb_str_split($textContent, ceil($textLength / $cell->getColspan()));
809809
foreach ($contentColumns as $position => $content) {
810810
$row[$i + $position] = $content;
811811
}

src/Symfony/Component/Console/Tests/Helper/TableTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ public static function renderProvider()
316316
],
317317
new TableSeparator(),
318318
[
319-
new TableCell('Cupiditate dicta atque porro, tempora exercitationem modi animi nulla nemo vel nihil!', ['colspan' => 3]),
319+
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]),
320320
],
321321
],
322322
'default',
@@ -333,7 +333,7 @@ public static function renderProvider()
333333
| 9971-5-0210-0 | A Tale of |
334334
| | Two Cities |
335335
+-------------------------------+-------------------------------+-----------------------------+
336-
| Cupiditate dicta atque porro, tempora exercitationem modi animi nulla nemo vel nihil! |
336+
| 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! |
337337
+-------------------------------+-------------------------------+-----------------------------+
338338

339339
TABLE

0 commit comments

Comments
 (0)
0