diff --git a/src/Symfony/Component/Console/Helper/Helper.php b/src/Symfony/Component/Console/Helper/Helper.php index ceef972b01..dc42600de8 100644 --- a/src/Symfony/Component/Console/Helper/Helper.php +++ b/src/Symfony/Component/Console/Helper/Helper.php @@ -41,7 +41,7 @@ abstract class Helper implements HelperInterface } /** - * Returns the length of a string, using mb_strlen if it is available. + * Returns the length of a string, using mb_strwidth if it is available. * * @param string $string The string to check its length * diff --git a/src/Symfony/Component/Console/Helper/TableHelper.php b/src/Symfony/Component/Console/Helper/TableHelper.php index 2fd6f5e900..3a9fbeeb18 100644 --- a/src/Symfony/Component/Console/Helper/TableHelper.php +++ b/src/Symfony/Component/Console/Helper/TableHelper.php @@ -387,8 +387,8 @@ class TableHelper extends Helper $width = $this->getColumnWidth($column); // str_pad won't work properly with multi-byte strings, we need to fix the padding - if (function_exists('mb_strlen') && false !== $encoding = mb_detect_encoding($cell)) { - $width += strlen($cell) - mb_strlen($cell, $encoding); + if (function_exists('mb_strwidth') && false !== $encoding = mb_detect_encoding($cell)) { + $width += strlen($cell) - mb_strwidth($cell, $encoding); } $width += $this->strlen($cell) - $this->computeLengthWithoutDecoration($cell); diff --git a/src/Symfony/Component/Console/Tests/Helper/TableHelperTest.php b/src/Symfony/Component/Console/Tests/Helper/TableHelperTest.php index 7a9eb40819..cd9e0f469d 100644 --- a/src/Symfony/Component/Console/Tests/Helper/TableHelperTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/TableHelperTest.php @@ -235,7 +235,7 @@ TABLE public function testRenderMultiByte() { - if (!function_exists('mb_strlen')) { + if (!function_exists('mb_strwidth')) { $this->markTestSkipped('The "mbstring" extension is not available'); } @@ -255,6 +255,33 @@ TABLE | 1234 | +------+ +TABLE; + + $this->assertEquals($expected, $this->getOutputContent($output)); + } + + public function testRenderFullWidthCharacters() + { + if (!function_exists('mb_strwidth')) { + $this->markTestSkipped('The "mbstring" extension is not available'); + } + + $table = new TableHelper(); + $table + ->setHeaders(array('あいうえお')) + ->setRows(array(array(1234567890))) + ->setLayout(TableHelper::LAYOUT_DEFAULT) + ; + $table->render($output = $this->getOutputStream()); + + $expected = + <<