From 8150678fa85a85f08992d620e11b64825df7f694 Mon Sep 17 00:00:00 2001 From: TBoileau Date: Thu, 21 Jul 2022 11:38:37 +0200 Subject: [PATCH] [String] Fix `width` method in `AbstractUnicodeString` --- .../Component/String/AbstractUnicodeString.php | 7 +++++-- .../String/Tests/AbstractUnicodeTestCase.php | 13 +++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/String/AbstractUnicodeString.php b/src/Symfony/Component/String/AbstractUnicodeString.php index 767f62320cd17..a482300d28682 100644 --- a/src/Symfony/Component/String/AbstractUnicodeString.php +++ b/src/Symfony/Component/String/AbstractUnicodeString.php @@ -498,8 +498,11 @@ public function width(bool $ignoreAnsiDecoration = true): int )|[\p{Cc}\x7F]++)/xu', '', $s); } - // Non printable characters have been dropped, so wcswidth cannot logically return -1. - $width += $this->wcswidth($s); + $lineWidth = $this->wcswidth($s); + + if ($lineWidth > $width) { + $width = $lineWidth; + } } return $width; diff --git a/src/Symfony/Component/String/Tests/AbstractUnicodeTestCase.php b/src/Symfony/Component/String/Tests/AbstractUnicodeTestCase.php index d6ec38461dbcf..d8f71ffd93d6a 100644 --- a/src/Symfony/Component/String/Tests/AbstractUnicodeTestCase.php +++ b/src/Symfony/Component/String/Tests/AbstractUnicodeTestCase.php @@ -15,6 +15,19 @@ abstract class AbstractUnicodeTestCase extends AbstractAsciiTestCase { + public static function provideWidth(): array + { + return array_merge( + parent::provideWidth(), + [ + [14, '<<expectException(InvalidArgumentException::class); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy