From d8111acc99876953f52fe16d4c50eb60940d49ad Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Thu, 24 Feb 2022 13:45:35 +0100 Subject: [PATCH] [Console] Fix null handling in formatAndWrap() --- Formatter/OutputFormatter.php | 4 ++++ Tests/Formatter/OutputFormatterTest.php | 1 + 2 files changed, 5 insertions(+) diff --git a/Formatter/OutputFormatter.php b/Formatter/OutputFormatter.php index 02cc8d76a..603e5dca0 100644 --- a/Formatter/OutputFormatter.php +++ b/Formatter/OutputFormatter.php @@ -140,6 +140,10 @@ public function format(?string $message) */ public function formatAndWrap(?string $message, int $width) { + if (null === $message) { + return ''; + } + $offset = 0; $output = ''; $openTagRegex = '[a-z](?:[^\\\\<>]*+ | \\\\.)*'; diff --git a/Tests/Formatter/OutputFormatterTest.php b/Tests/Formatter/OutputFormatterTest.php index 3ad18b897..21970f79e 100644 --- a/Tests/Formatter/OutputFormatterTest.php +++ b/Tests/Formatter/OutputFormatterTest.php @@ -343,6 +343,7 @@ public function testFormatAndWrap() $this->assertSame("pre\nfoo\nbar\nbaz\npos\nt", $formatter->formatAndWrap('pre foo bar baz post', 3)); $this->assertSame("pre \nfoo \nbar \nbaz \npost", $formatter->formatAndWrap('pre foo bar baz post', 4)); $this->assertSame("pre f\noo ba\nr baz\npost", $formatter->formatAndWrap('pre foo bar baz post', 5)); + $this->assertSame('', $formatter->formatAndWrap(null, 5)); } }