8000 issues/60038: Table counts wrong number of padding symbols in method … · symfony/symfony@13801ad · GitHub
[go: up one dir, main page]

Skip to content

Commit 13801ad

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 1e812e6 commit 13801ad

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
@@ -562,7 +562,7 @@ private function renderCell(array $row, int $column, string $cellFormat): string
562562

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

568568
$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
@@ -2092,4 +2092,36 @@ public function testGithubIssue52101HorizontalFalse()
20922092
$this->getOutputContent($output)
20932093
);
20942094
}
2095+
2096+
public function testGithubIssue60038WidthOfCellWithEmoji()
2097+
{
2098+
$table = (new Table($output = $this->getOutputStream()))
2099+
->setHeaderTitle('Test Title')
2100+
->setHeaders(['Title', 'Author'])
2101+
->setRows([
2102+
["🎭 💫 ☯"." Divine Comedy", "Dante Alighieri"],
2103+
// the snowflake (e2 9d 84 ef b8 8f) has a variant selector
2104+
["👑 ❄️ 🗡"." Game of Thrones", "George R.R. Martin"],
2105+
// the snowflake in text style (e2 9d 84 ef b8 8e) has a variant selector
2106+
["❄︎❄︎❄︎ snowflake in text style ❄︎❄︎❄︎", ""],
2107+
["And a very long line to show difference in previous lines", ""],
2108+
])
2109+
;
2110+
$table->render();
2111+
2112+
$this->assertSame(<<<TABLE
2113+
+---------------------------------- Test Title -------------+--------------------+
2114+
| Title | Author |
2115+
+-----------------------------------------------------------+--------------------+
2116+
| 🎭 💫 ☯ Divine Comedy | Dante Alighieri |
2117+
| 👑 ❄️ 🗡 Game of Thrones | George R.R. Martin |
2118+
| ❄︎❄︎❄︎ snowflake in text style ❄︎❄︎❄︎ | |
2119+
| And a very long line to show difference in previous lines | |
2120+
+-----------------------------------------------------------+--------------------+
2121+
2122+
TABLE
2123+
,
2124+
$this->getOutputContent($output)
2125+
);
2126+
}
20952127
}

0 commit comments

Comments
 (0)
0