Skip to content

Commit 5eb661e

Browse files
TBoileaufabpot
authored andcommitted
[String] Fix width method in AbstractUnicodeString
1 parent 9091cb2 commit 5eb661e

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

AbstractUnicodeString.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,11 @@ public function width(bool $ignoreAnsiDecoration = true): int
498498
)|[\p{Cc}\x7F]++)/xu', '', $s);
499499
}
500500

501-
// Non printable characters have been dropped, so wcswidth cannot logically return -1.
502-
$width += $this->wcswidth($s);
501+
$lineWidth = $this->wcswidth($s);
502+
503+
if ($lineWidth > $width) {
504+
$width = $lineWidth;
505+
}
503506
}
504507

505508
return $width;

Tests/AbstractUnicodeTestCase.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@
1515

1616
abstract class AbstractUnicodeTestCase extends AbstractAsciiTestCase
1717
{
18+
public static function provideWidth(): array
19+
{
20+
return array_merge(
21+
parent::provideWidth(),
22+
[
23+
[14, '<<<END
24+
This is a
25+
multiline text
26+
END'],
27+
]
28+
);
29+
}
30+
1831
public function testCreateFromStringWithInvalidUtf8Input()
1932
{
2033
$this->expectException(InvalidArgumentException::class);

0 commit comments

Comments
 (0)