Skip to content

Commit 6df2f4b

Browse files
committed
bug symfony#54435 [Console] respect multi-byte characters when rendering vertical-style tables (xabbuh)
This PR was merged into the 6.4 branch. Discussion ---------- [Console] respect multi-byte characters when rendering vertical-style tables | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix symfony#54433 | License | MIT Commits ------- a98a616 respect multi-byte characters when rendering vertical-style tables
2 parents c3eb7ac + a98a616 commit 6df2f4b

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,9 @@ public function render()
371371
if ($headers && !$containsColspan) {
372372
if (0 === $idx) {
373373
$rows[] = [sprintf(
374-
'<comment>%s</>: %s',
375-
str_pad($headers[$i] ?? '', $maxHeaderLength, ' ', \STR_PAD_LEFT),
374+
'<comment>%s%s</>: %s',
375+
str_repeat(' ', $maxHeaderLength - Helper::width(Helper::removeDecoration($formatter, $headers[$i] ?? ''))),
376+
$headers[$i] ?? '',
376377
$part
377378
)];
378379
} else {

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,6 +1649,28 @@ public static function provideRenderVerticalTests(): \Traversable
16491649
$books,
16501650
];
16511651

1652+
yield 'With multibyte characters in some headers (the "í" in "Títle") and cells (the "í" in "Dívíne")' => [
1653+
<<<EOTXT
1654+
+-------------------------+
1655+
| ISBN: 99921-58-10-7 |
1656+
| Títle: Dívíne Comedy |
1657+
| Author: Dante Alighieri |
1658+
| Price: 9.95 |
1659+
+-------------------------+
1660+
1661+
EOTXT
1662+
,
1663+
['ISBN', 'Títle', 'Author', 'Price'],
1664+
[
1665+
[
1666+
'99921-58-10-7',
1667+
'Dívíne Comedy',
1668+
'Dante Alighieri',
1669+
'9.95',
1670+
],
1671+
],
1672+
];
1673+
16521674
yield 'With header for some' => [
16531675
<<<EOTXT
16541676
+------------------------------+

0 commit comments

Comments
 (0)