Skip to content

Commit cfe2fcc

Browse files
bug #61319 [Console] [Table] Don't split grapheme clusters (schlndh)
This PR was merged into the 6.4 branch. Discussion ---------- [Console] [Table] Don't split grapheme clusters | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | | License | MIT This change prevents splitting of grapheme clusters due to wrapping in Table. The emoji consists of multiple code points, so `CodePointString` chunked it into multiple pieces and wordrap then split them into separate lines. E.g.: ``` --- Expected +++ Actual @@ @@ -'👩‍🌾' +'👩 +‍ +🌾' ``` Commits ------- c258c19 [Console][Table] Don't split grapheme clusters
2 parents ad80125 + c258c19 commit cfe2fcc

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/Symfony/Component/Console/Formatter/OutputFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,6 @@ private function addLineBreaks(string $text, int $width): string
285285
{
286286
$encoding = mb_detect_encoding($text, null, true) ?: 'UTF-8';
287287

288-
return b($text)->toCodePointString($encoding)->wordwrap($width, "\n", true)->toByteString($encoding);
288+
return b($text)->toUnicodeString($encoding)->wordwrap($width, "\n", true)->toByteString($encoding);
289289
}
290290
}

src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ public function testFormatAndWrap()
373373
$this->assertSame("foobar\e[37;41mbaz\e[39;49m\n\e[37;41mnewline\e[39;49m", $formatter->formatAndWrap("foobar<error>baz\nnewline</error>", 11));
374374
$this->assertSame("foobar\e[37;41mbazne\e[39;49m\n\e[37;41mwline\e[39;49m", $formatter->formatAndWrap("foobar<error>bazne\nwline</error>", 11));
375375
$this->assertSame("foobar\e[37;41mbazne\e[39;49m\n\e[37;41mw\e[39;49m\n\e[37;41mline\e[39;49m", $formatter->formatAndWrap("foobar<error>baznew\nline</error>", 11));
376+
$this->assertSame("\e[37;41m👩‍🌾\e[39;49m", $formatter->formatAndWrap('<error>👩‍🌾</error>', 1));
376377

377378
$formatter = new OutputFormatter();
378379

@@ -392,6 +393,7 @@ public function testFormatAndWrap()
392393
$this->assertSame("foobarbaz\nnewline", $formatter->formatAndWrap("foobar<error>baz\nnewline</error>", 11));
393394
$this->assertSame("foobarbazne\nwline", $formatter->formatAndWrap("foobar<error>bazne\nwline</error>", 11));
394395
$this->assertSame("foobarbazne\nw\nline", $formatter->formatAndWrap("foobar<error>baznew\nline</error>", 11));
396+
$this->assertSame('👩‍🌾', $formatter->formatAndWrap('👩‍🌾', 1));
395397
}
396398
}
397399

0 commit comments

Comments
 (0)