Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Console] Table counts wrong number of padding symbols in renderCell() method when cell contain unicode variant selector #60042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 6.4
Choose a base branch
Loading
from
Open
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 2 src/Symfony/Component/Console/Helper/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,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) - mb_strwidth($cell, $encoding) + substr_count($cell, "\xef\xb8\x8f") + substr_count($cell, "\xef\xb8\x8e");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exactly does the unicode sequence \xef\xb8\x8e refer to?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These U+FE0F, U+FE0E selectors are used to display emoji with color or monochrome. As I can see usually the U+FE0E selector is skipped.
Example with snowflake:
U+2744 ❄ e2 9d 84
U+2744 ❄ e2 9d 84 ef b8 8e
U+2744 ❄️ e2 9d 84 ef b8 8f

}

$style = $this->getColumnStyle($column);
Expand Down
32 changes: 32 additions & 0 deletions 32 src/Symfony/Component/Console/Tests/Helper/TableTest.php
Original file line number Diff line number Diff line change
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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.