Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,7 @@ private function splitStringByWidth(string $string, int $width): array

foreach (preg_split('//u', $m[0]) as $char) {
// test if $char could be appended to current line
if (mb_strwidth($line.$char, 'utf8') <= $width) {
if (Helper::width($line.$char) <= $width) {
$line .= $char;
continue;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Symfony/Component/Console/Helper/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public static function width(?string $string): int
$string ??= '';

if (preg_match('//u', $string)) {
return (new UnicodeString($string))->width(false);
$string = preg_replace('/[\p{Cc}\x7F]++/u', '', $string, -1, $count);

return (new UnicodeString($string))->width(false) + $count;
}

if (false === $encoding = mb_detect_encoding($string, null, true)) {
Expand Down
5 changes: 1 addition & 4 deletions src/Symfony/Component/Console/Helper/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -564,10 +564,7 @@ private function renderCell(array $row, int $column, string $cellFormat): string
}

// str_pad won't work properly with multi-byte strings, we need to fix the padding
if (false !== $encoding = mb_detect_encoding($cell, null, true)) {
$width += \strlen($cell) - mb_strwidth($cell, $encoding);
}

$width += \strlen($cell) - Helper::width($cell) - substr_count($cell, "\0");
$style = $this->getColumnStyle($column);

if ($cell instanceof TableSeparator) {
Expand Down
36 changes: 34 additions & 2 deletions src/Symfony/Component/Console/Tests/Helper/TableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1294,9 +1294,9 @@ public static function renderSetTitle()
'footer',
'default',
<<<'TABLE'
+---------------+---- Multiline
+---------------+--- Multiline
header
here -+------------------+
here +------------------+
| ISBN | Title | Author |
+---------------+--------------------------+------------------+
| 99921-58-10-7 | Divine Comedy | Dante Alighieri |
Expand Down Expand Up @@ -2078,4 +2078,36 @@ public function testGithubIssue52101HorizontalFalse()
$this->getOutputContent($output)
);
}

public function testGithubIssue60038WidthOfCellWithEmoji()
{
$table = (new Table($output = $this->getOutputStream()))
->setHeaderTitle('Test Title')
->setHeaders(['Title', 'Author'])
->setRows([
["🎭 πŸ’« ☯"." Divine Comedy", "Dante Alighieri"],
// the snowflake (e2 9d 84 ef b8 8f) has a variant selector
["πŸ‘‘ ❄️ πŸ—‘"." Game of Thrones", "George R.R. Martin"],
// the snowflake in text style (e2 9d 84 ef b8 8e) has a variant selector
["β„οΈŽβ„οΈŽβ„οΈŽ snowflake in text style β„οΈŽβ„οΈŽβ„οΈŽ", ""],
["And a very long line to show difference in previous lines", ""],
])
;
$table->render();

$this->assertSame(<<<TABLE
+---------------------------------- Test Title -------------+--------------------+
| Title | Author |
+-----------------------------------------------------------+--------------------+
| 🎭 πŸ’« ☯ Divine Comedy | Dante Alighieri |
| πŸ‘‘ ❄️ πŸ—‘ Game of Thrones | George R.R. Martin |
| β„οΈŽβ„οΈŽβ„οΈŽ snowflake in text style β„οΈŽβ„οΈŽβ„οΈŽ | |
| And a very long line to show difference in previous lines | |
+-----------------------------------------------------------+--------------------+

TABLE
,
$this->getOutputContent($output)
);
}
}
Loading