Skip to content

Commit 61b01a8

Browse files
committed
issues/60038: Table counts wrong number of padding symbols in method renderCell(..) when cell contain unicode variant selector. With testcase.
1 parent fc8f7a0 commit 61b01a8

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ private function renderCell(array $row, int $column, string $cellFormat): string
565565

566566
// str_pad won't work properly with multi-byte strings, we need to fix the padding
567567
if (false !== $encoding = mb_detect_encoding($cell, null, true)) {
568-
$width += \strlen($cell) - mb_strwidth(str_replace(["\xef\xb8\x8f", "\xef\xb8\x8e", ], "", $cell), $encoding);
568+
$width += \strlen($cell) - mb_strwidth($cell, $encoding) + substr_count($cell, "\xef\xb8\x8f") + substr_count($cell, "\xef\xb8\x8e");
569569
}
570570

571571
$style = $this->getColumnStyle($column);

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,4 +2078,36 @@ public function testGithubIssue52101HorizontalFalse()
20782078
$this->getOutputContent($output)
20792079
);
20802080
}
2081+
2082+
public function testGithubIssue60038WidthOfCellWithEmoji()
2083+
{
2084+
$table = (new Table($output = $this->getOutputStream()))
2085+
->setHeaderTitle('Test Title')
2086+
->setHeaders(['Title', 'Author'])
2087+
->setRows([
2088+
["🎭 💫 ☯"." Divine Comedy", "Dante Alighieri"],
2089+
// the snowflake (e2 9d 84 ef b8 8f) has a variant selector
2090+
["👑 ❄️ 🗡"." Game of Thrones", "George R.R. Martin"],
2091+
// the snowflake in text style (e2 9d 84 ef b8 8e) has a variant selector
2092+
["❄︎❄︎❄︎ snowflake in text style ❄︎❄︎❄︎", ""],
2093+
["And a very long line to show difference in previous lines", ""],
2094+
])
2095+
;
2096+
$table->render();
2097+
2098+
$this->assertSame(<<<TABLE
2099+
+---------------------------------- Test Title -------------+--------------------+
2100+
| Title | Author |
2101+
+-----------------------------------------------------------+--------------------+
2102+
| 🎭 💫 ☯ Divine Comedy | Dante Alighieri |
2103+
| 👑 ❄️ 🗡 Game of Thrones | George R.R. Martin |
2104+
| ❄︎❄︎❄︎ snowflake in text style ❄︎❄︎❄︎ | |
2105+
| And a very long line to show difference in previous lines | |
2106+
+-----------------------------------------------------------+--------------------+
2107+
2108+
TABLE
2109+
,
2110+
$this->getOutputContent($output)
2111+
);
2112+
}
20812113
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy